Jump to content

Recommended Posts

Hey guys im trying to create a dropdown box which is populated by my database of members

 

here is the code i have so far, right now it is only displaying 1 member instead of all of them. also in the end i would like the drop down values to be "Membername(data joined)"

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("clients", $con);

    
$extract = mysql_query ("SELECT * FROM members");
$numrows = mysql_num_rows ($extract);

echo"Select USER: <select name='site'>";

while ($row = mysql_fetch_assoc($extract))
{
$site = $row['firstname'];
}	

echo"<option name='$site'>$site</option> ";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/182860-populating-dropdown-via-database/
Share on other sites

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("clients", $con);

    
$extract = mysql_query ("SELECT * FROM members");
$numrows = mysql_num_rows ($extract);

echo"Select USER: <select name='site'>";

while ($row = mysql_fetch_assoc($extract))
{
  echo"<option name='$row['firstname']>$row['firstname']</option> ";
}      

?>

woops

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("clients", $con);

    
$extract = mysql_query ("SELECT * FROM members");
$numrows = mysql_num_rows ($extract);

echo"Select USER: <select name='site'>";

while ($row = mysql_fetch_assoc($extract))
{
  echo"<option name='$row['firstname']'>$row['firstname']</option> ";
}      

?>

:shrug:

 

im getting "Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\homepage\work.php on line 18"

 

line 18 is

  echo"<option name='$row['firstname']>$row['firstname']</option> ";

 

so i changed the line to this :

  echo"<option name='$row[firstname]>$row[firstname]</option> ";

 

and the drop box works now but it only shows the first member and no one else

 

 

how would i arrange them by newest to oldest using another column in my database

 

It should be order by newest, descending if you have a auto-incrementing column in your `members` table. If not, add a column to your `members` table, call it `userid`, set it to INT with a length of 10, and select it auto-increment and make it a primary key.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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