Jump to content

Recommended Posts

Hello All,

  I am working on some output from an MYSQL table to auto display the info from a table.

Here is my code.

 

$sql0 = "SELECT * FROM userlogin ORDER BY `ID` DESC LIMIT 0,1";

$sql1 = "SELECT * FROM userlogin ORDER BY `ID` DESC LIMIT 1,2";

 

$query0 = mysql_query($sql0);

$query1 = mysql_query($sql1);

 

$row0 = mysql_fetch_array($query0);

$row2 = mysql_fetch_array($query2);

 

Every time I go over my display query limit I have to add new ones.

 

How would I create something so it will automatic pulls from the database table and automatically shows in my drop down box the new fields I add to the table.

 

This is the part that is for the drop down box.

 

<option value="<?echo $row0['username']; ?>"><?echo $row0['username']; ?></option>

<option value="<?echo $row1['username']; ?>"><?echo $row1['username']; ?></option>

 

I am new at this so let me know if there is something I can do different.

 

Thank you

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/56459-dynamic-display-from-mysql-in-an-aray/
Share on other sites

<?php

  $sql = "SELECT * FROM userlogin ORDER BY `ID` DESC";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        echo "<option value=\"{$row['username']}\">{$row['username']}</option>";
      }
    }
  }

?>

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.