Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/228589-mysql-list-contents-of-a-feild/
Share on other sites

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).

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.