You are here: Re: Challenge: MySql result to drop down box « All PHP « IT news, forums, messages
Re: Challenge: MySql result to drop down box

Posted by shubeer on 07/14/06 14:19

I seem to have got my knickers in a knot and posted some incorrect
code. Well, this is actually how I would have written the code:

<?php
1: mysql_connect("localhost", "uname", "pword") or die("Died
connecting");
2: mysql_select_db("test");
3: $res=mysql_query("SELECT id, value FROM test_table") or die("Query
failed");
4: print "<select name='jobname'>".
5: "<option selected='selected'>Choose One</option>";
6: while($row = mysql_fetch_assoc($res)) {
7: print "<option value='{$row[id]}'>{$row[value]}</option>";
8: }
9: print "</select>";
10:mysql_close();
?>

As mentioned, we could also add further error checking to this code,
but this is just to illustrate the point. Also, it's not exactly the
same code you posted, but it tries to accomplish the same thing.

With previous experience if the $row[id] is changed to $row[ID] this
will not give the intended result, therefore your index into the $row
associative array must match the columns returned by your query exactly
(yes, including case)

 

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

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