searls03 Posted June 5, 2011 Share Posted June 5, 2011 I have never tried this before, but I must now.....how do I make a select list that will display all results from the table pictures but I only need the row "event". make sense? please help? Quote Link to comment https://forums.phpfreaks.com/topic/238484-select-list-with-all-results/ Share on other sites More sharing options...
ManiacDan Posted June 5, 2011 Share Posted June 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238484-select-list-with-all-results/#findComment-1225478 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238484-select-list-with-all-results/#findComment-1225480 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 $row = ("SELECT `event`FROM `pictures` WHERE id='.$id.'; print_r($row); Quote Link to comment https://forums.phpfreaks.com/topic/238484-select-list-with-all-results/#findComment-1225482 Share on other sites More sharing options...
mikesta707 Posted June 5, 2011 Share Posted June 5, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/238484-select-list-with-all-results/#findComment-1225517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.