Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
$_GET being confused by URL in code
Old 12-15-2007, 05:34 PM $_GET being confused by URL in code
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
I am having trouble getting php to bold one <a> without doing all of them. Heres part of my code:
PHP Code:
<a href="index.php?pagecall=browsegen.php&qualifier=Action/Adventure">- Action/Adventure</a><br />
<
a href="index.php?pagecall=browsegen.php&qualifier=Animation">- Animation</a><br />
<
a href="index.php?pagecall=browsegen.php&qualifier=Comedy">- Comedy</a><br />
<
a href="index.php?pagecall=browsegen.php&qualifier=Documentary">- Documentary</a><br /> 
I am basically letting a user pick a movie genre from a list and then it loads the page and I want the menu item that was selected to be bolded.

I have tried several variations of
PHP Code:
if ($_GET['qualifier']="Animation") {
echo 
"<b>- Action/Adventure</b>"}
else
{echo 
"- Action/Adventure"
What happends tho, is because $qualifier is in the url just before it for some reason assumes that its been set, even though there is nothing in the URL.

Any suggestions?
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-15-2007, 06:50 PM Re: $_GET being confused by URL in code
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Use urlencode.

Example:
PHP Code:
<a href="index.php?pagecall=browsegen.php&qualifier=<?php echo urlencode("Action/Adventure"); ?>">- Action/Adventure</a><br />
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 12-15-2007 at 06:51 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 12-15-2007, 07:22 PM Re: $_GET being confused by URL in code
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
The problems lies in your if statement, as you do not check weather or not $_GET['qualifier'] equals to a value, but give it a value. In short, you forgot one equals sign (=).

You could also write that if statment a bit shorter, for example
PHP Code:
echo "<a href=\"...your url...\">"
    
.($_GET['qualifier'] == "value") ? "<b>value</b>" "value"
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-15-2007, 09:07 PM Re: $_GET being confused by URL in code
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
missing an = sign, hahaha thats such a stupid mistake buts thats what it always is isnt it? (at least for me ). I tried the other code too "urlencode" and that works. But what exactly does urlencode do. Like why would I use taht as opposed to just doing it the correct way with the ==?

Thanks again for the quick responses quys
Truly is offline
Reply With Quote
View Public Profile
 
Old 12-16-2007, 04:44 PM Re: $_GET being confused by URL in code
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I don't really see any point in using urlencode(), I can't figure how rogem002 was thinking. Please correct me if I'm missing something. All that urlencode() does, is exactly what it's name says. It encodes a string to an url. That is, it replaces non alphanumeric (except some, like . or _) values with a % followed by two hex digits. Spaces are replaced with a plus sign. (All this can also be read at php.net).
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-16-2007, 09:39 PM Re: $_GET being confused by URL in code
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You can simplify your coding by using an array like this:

PHP Code:
<?php
  
  $qualifier_array 
= array('Action/Adventure''Animation''Comedy''Documentary');
  
  foreach (
$qualifier_array AS $value)
  {
    echo 
'<a href="index.php?pagecall=browsegen.php&qualifier=' urlencode($value) . '">- ' . (($_GET['qualifier'] == $value) ? "<strong>$value</strong>" $value) . "</a><br />\n";
  }
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-17-2007, 12:04 PM Re: $_GET being confused by URL in code
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Cool thanks mgraphic that worked good. And lizciz I think they did it because theres a / in some of them which will screw up the browser. I guess I couldve just added the % myself but this is easier.
Truly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to $_GET being confused by URL in code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24873 seconds with 12 queries