Jump to content

select list with all results


searls03

Recommended Posts

You need to get your terminology straight, and be a little more clear.  A "row" and  "result" are the same thing.

 

Are you saying you want a PHP script that selects a single COLUMN (not row) from a database table and spits out a select box with every value from that column?

 

What have you tried so far?  Do you know how to query a database and/or print HTML from PHP?

 

-Dan

Link to comment
Share on other sites

sorry, here is the code that pulls things from database(ignore $content please:

<?php
include_once "connect_to_mysql.php";

// if no id is specified, list the available articles


   $query = "SELECT image, event, name, id, site FROM pictures where id='".$_GET['id']."'";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value=value='".$row['userid']."' /><li><img src='$image'/></a></li>";
   }
   ?>

 

When I referred to row, I was referring to the table column from the database, not the result.  and yes, I would like it to select from one column and spit all it out.  sorry for confusion, I forget that people cant read my mind.  haha.

Link to comment
Share on other sites

$row = ("SELECT `event`FROM `pictures` WHERE id='.$id.';

print_r($row);

 

what is this? This really doesn't have anything to do with OP's question, and in fact has a syntax error in it. Even if you did have correct syntax, all this would do is display that $row is a string, and print the contents of the string?

 

Anyways, for OP, printing out a select box with the info you want is fairly easy. I'll give an example

 

$sql = "SELECT something FROM somewhere WHERE somecolumn='somevalue'";
$res = mysql_query($sql);
echo "<select name='someName' ... >";//print out begining select tag once
while($row = mysql_fetch_array($res)){
echo "<option value='".$row['column_you_want']."' >".$row['column_you_want']."</option>";//print each option for every row
}
echo "</select>";//print out closing select tag

 

Hope this helps

Link to comment
Share on other sites

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.