Jump to content

printing tables


wazza91

Recommended Posts

hi i have this code here and i was wondering how i could make it print out the values from my database using a drop down menu.

i no this is probably very basic but im a real novice at php and sql.

 

 

<?php

mysql_connect('localhost', 'root', '');

mysql_select_db('charity_data');

$result = mysql_query('select * from donations');

?>

<select name="selectname">

<?php

$i = 0;

while ($i < mysql_num_fields($result)){

  $fieldname = mysql_field_name($result, $i);

  echo '<option value="'.$fieldname.'">'.$fieldname.'</option>';

  $i++;

}

 

 

 

?>

 

 

 

 

</select>

Link to comment
https://forums.phpfreaks.com/topic/233604-printing-tables/
Share on other sites

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('charity_data');
$result = mysql_query('select * from donations');
?>

<select name="selectname">
<?php
while ($row = mysql_fetch_assoc($result)){
  
  echo "<option value='whatever'>".$row['databasefield']."</option>";


}
?>
</select>

Link to comment
https://forums.phpfreaks.com/topic/233604-printing-tables/#findComment-1201172
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.