|
Posted by Gazelem on 01/04/06 01:27
Leszek wrote:
> Hi.
> How can I get just one row from selected column and put it into html
> dropdown list
> I tried like this:
>
> function pobierz_wszystko($tabela,$kolumna)
> {
> $zapytanie="SELECT $kolumna FROM $tabela";
> $wynik=mysql_query($zapytanie);
> while($wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC))
> {
> echo "<option value=$wiersz>$wiersz</option> <br />";
> }
> }
The query is wrong among other things.
proper: Select $kolumna from $tabela limit 1
You can also use an offset, reference the manual at
http://dev.mysql.com/doc/refman/4.1/en/select.html
Another thing is, if you are *always* going to want just one result, not
only should you use the proper select, but you should also limit your code
to only ask for 1 result:
$wynik=mysql_query($zapytanie);
$wiersz=mysql_fetch_array($wynik,MYSQL_ASSOC)
echo "<option value=$wiersz>$wiersz</option> <br />";
notice the lack of using a "while" statement, which is not appropriate for 1
result queries.
-Dave
[Back to original message]
|