You are here: Re: How can I get just one row from selected column? « PHP SQL « IT news, forums, messages
Re: How can I get just one row from selected column?

Posted by Hilarion on 10/14/77 11:36

>> 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.


I think that Leszek wanted to ask "how can I get just one COLUMN from...",
in which case LIMIT clause will not be what he looks for.
As others explained - Leszek used the PHP mysql functions output in
a wrong way, and it had nothing to do with SQL syntax.


Hilarion

 

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

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