You are here: Re: change space to hyphen in sql query results « All PHP « IT news, forums, messages
Re: change space to hyphen in sql query results

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация