How to echo all fields/rows from a MYSQL Table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

How to echo all fields/rows from a MYSQL Table?

Post by kaisellgren »

Hello!

I need to make a listbox including all fields/rows/whatever in a table. The code I have so far:

Code: Select all

<?php

foreach ( as $item)
 {
  echo '<option value="'.$item.'">'.$item.'</option>';
 }
?>
Can someone quickly "fill" my code?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

if you want the field names, use something like 'desc %tablename%' for your query.

if you want the values, then just use a standard select.

you'll then need to loop over your query using a while loop (not a foreach) and display the results within your loop.
Post Reply