Posted by J.O. Aho on 01/01/06 22:20
emmakane@gmail.com wrote:
> I am teaching myself PHP and am I am stuck trying to do the following.
> I have the following code which pulls all the names of items in my
> database and puts them in a hyperlinked list. I then want to be able to
> click on a hyperling and use another script to search the database for
> other instances of the item. The only trouble is the result $get[name]
> in the url has spaces which are then ignored by the browser query.
>
> <?
> require "config.php"; // All database details will be
> included here
> $page_name="test.php"; //
> $query="SELECT name FROM database1 ";
> $result=mysql_query($query);
> echo mysql_error();
> while($get = mysql_fetch_array($result))
> {
> echo "<a
> href=http://www.myurl.com/search.php?q=$get[name]&Search=Search>$get[name]<br>";
>
> }
> ?>
Why not use the ID for the row instead, the "url" will get shorter, no
problems with spaces or any other characters. This of course would most likly
result in an extra sql query, but I would rather have that than unexpected
results.
href=http://www.myurl.com/search.php?q=$get[id]&Search=Search>$get[name]<br>";
Otherwise you need to regex spaces and most likely chars >127 to their ASCII
values, I think %E20 would be a space.
//Aho
[Back to original message]
|