kennsi942 Posted February 23, 2011 Share Posted February 23, 2011 Hi i want to make a form LIST that automaticly gets the content "orderid" to choose for editing. can i please get a pointing pin on which function(s) to use ? i have tried with: $result = mysql_query("SELECT * FROM {$table} WHERE 'ordreid'"); if (!$result) { die("Query to show fields from table failed"); } echo($result); $i = 0; while($i<mysql_num_fields($result)) { $meta=mysql_fetch_field($result,$i); echo $i.".".$meta->name."<br />"; $i++; } like i want to get this part: <option>first item in field orderid</option> <option>2'nd item in field orderid</option> and so on...i know its easy but i have struggled wit this enough now. Quote Link to comment https://forums.phpfreaks.com/topic/228589-mysql-list-contents-of-a-feild/ Share on other sites More sharing options...
Muddy_Funster Posted February 23, 2011 Share Posted February 23, 2011 first off, welcome to the forum. now to the code : you can't just echo $result. You need to look at how your getting your output from the database to the screen from a different angle. also, you've kinda neglected to mention what $meta is all about. $result = mysql_query("SELECT * FROM {$table} WHERE 'ordreid'"); if (!$result) { die("Query to show fields from table failed"); } echo($result); $i = 0; while($i<mysql_num_fields($result)) { $meta=mysql_fetch_field($result,$i); echo $i.".".$meta->name."<br />"; $i++; } should look more like: $qry = "SELECT id_field, name_field FROM ".$table; $result = mysql_query($qry); if (!$result) { die("Query to show fields from table failed with following error --".mysql_error() ); } while($row = mysql_fetch_assoc($result)) { echo '<option value="'.$row['id_field'].'">'.$row['name_filed'].'</option>'; } Take time and look through example code and some manuals to get a better understanding of what's going on here. It sounds dull, but is no more time consuming that trying to work out what the problem is on your own (although it is marginaly less frustrating). Quote Link to comment https://forums.phpfreaks.com/topic/228589-mysql-list-contents-of-a-feild/#findComment-1178600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.