[web] Help - PHP

Started by
4 comments, last by evolutional 19 years, 7 months ago
I'm trying to make links dynamically where when you click them they reload the page passing an argument. Ala:

for($rankIndex = 1; $rankIndex <= 5; $rankIndex++) {
    echo($ranks[$rankIndex] . "<br>");
    while($memberNames[$rankIndex][$index] != "" && $memberNames[$rankIndex][$index] != "_DEFAULT") {
      $name = $memberNames[$rankIndex][$index];
      echo("<a href=$memberPage?profile=$name>$name</a><br>");
      $index++;
    }
    echo("<br>");
  }


The problem is $memberNames[$rankIndex][$index] has more than one word. Like "Joe Schmoe" and it is only setting ?profile to the first part.. ala ?profile=Joe instead of ?profile=Joe%20Schmoe. How do I fix that? I kinda know whats wrong and have tried doing ?profile=\"$name\" but that just does ?profile="Joe. The $name as the link text works just fine, displaying the whole string. Any help is appreciated.
-Going to Westwood College for my Associates in Computer Programming
Advertisement
Try apostrophes. ' '
Tried that as well, had same result as double quotes. It just said ?profile='Joe
-Going to Westwood College for my Associates in Computer Programming
You'll have to urlencode the string for the link, swapping spaces for the %20 equivalent otherwise this sort of behaviour is expected. Likewise, on the page that takes the string as GET input, you'll need to call urldecode
You have to urlencode stuff in query strings in links.

But you don't have to urldecode it when it comes back in, it is automatically decoded by PHP, so

$_GET['profile']

Will contain it already decoded.

Mark
Cheers Mark, I learn new things every day ^_-

This topic is closed to new replies.

Advertisement