madspof Posted April 27, 2007 Share Posted April 27, 2007 Is it possible for php to list the content in a row in a drop down list maybye using an array im not sure can anyone help. plz Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/ Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 please anyne a few pointer to go off Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240042 Share on other sites More sharing options...
snowdog Posted April 27, 2007 Share Posted April 27, 2007 This is what I have done to populate a drop down menu in one of my files. I hope that is what you were asking....Snowdog <select style="width:350px;" name="call_download"> <? $query = "select * from call_reminder WHERE date >= '$start_date' AND date <= '$end_date' AND member_group = '$show_userdata->member_group' AND completed = '1' ORDER BY date DESC"; $result_group = mysql_query($query) or die('Query failed: ' . mysql_error()); while($show_group = mysql_fetch_object($result_group)) { $call = $show_group->call; $title = $show_group->title; $filename = $show_group->id; echo("<option value='$filename'>$call - $title</option>"); } ?> </select> Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240045 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 Is there a way of explaining what goes on in this script am nt the best with php but i understand most of it thnks madspof Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240047 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 I have this code so far but i t does not seem to work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php // Set the various database connect information. Host is usually // localhost. If no password, just leave blank. This information is // given by your web host OR if your own server, you setup yourself. // See php manual for setup instructions. $db_host = 'localhost'; $db_user = 'cms'; $db_pass = ''; $db_name = 'phpsms'; // More then one table can be used but in ths example we use just // one. :-) And in many scripts just one is used. And it's easiest // to comment on. $db_table = 'userdata'; // ---- END CONFIGURATIONS ------------------------------------------// // Make a connect to mysql. Through this connect many databases // and tables can be selected. $conn will be what we call this // connection. $conn = mysql_connect($db_host,$db_user,$db_pass); if ($conn == true) { // Select the database. mysql_select_db($db_name,$conn); // We are selecting all fields (*) from database and using the $conn // database connection. By default $conn would be used but we're // learning so may as well not be lazy :-) Usually you wouldn't // select * but for the lazy and unsure, it works nicely. // // This is a very powerful function, one can query *any* SQL statement // and do many things, like update/delete/insert/select data. A good // basic SQL tutorial is : sqlcourse.com . The result of this // query is named $result $result = mysql_query("SELECT * from $db_table",$conn); // While a row exists to equal the fetched object (row) of data // continue to loop until end of fetch (at the end) // The way data is called may be new. $row->dbfieldname . See // the manual on mysql_fetch_object() for more info. Other functions // can just as easily have been used, like mysql_fetch_array. That method // one would use format as : $row['id']; , $row['name'] , etc. See manual // for all the possible (and beautiful) tools that are available. while($row = mysql_fetch_object($result)) { // These will loop through entire database. $tmp keeps getting // appended to so it's getting very large. This is what's printed // and where one makes look pretty :-) Below the database fields // id, name and url are being printed from the $db_table table. And, // the .= means it appends (concatenates) to $tmp so $tmp grows larger // and later. See : http://www.zend.com/zend/tut/using-strings.php // Again, id,name and url are just examples ... replace according to // your database. $users[] = $row->userid; // The while loop ends here at this brace so the above cycles through until // all data is gathered. } // Else we are not connected ($conn == false) so print error. } else { echo 'could not connect to database : '. mysql_error(); } // Print the pulled data. ?> <form name="form1" method="post" action="message1.php"> <p> <select name="select" size="1"> <? foreach($users AS $user){ ?> <option> <?=$user?> </option> <? } ?> </select> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> <p> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240054 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 Anyomne Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240064 Share on other sites More sharing options...
sanfly Posted April 27, 2007 Share Posted April 27, 2007 Well, firstly i would put my connection data in a different file, that can be easily included each time its needed eg: db.php <?php $db_host = 'localhost'; $db_user = '*****'; $db_pass = '*****'; $db_name = '*****'; $conn = mysql_connect($db_host,$db_user,$db_pass) or die("Cannot Connect to database"); $db = mysql_select_db($db_name,$conn) or die("Could not select database"); ?> Then I would do the select box as below <form name="form1" method="post" action="message1.php"> <select name="selectUser" size="1"> <? include "db.php"; $result = mysql_query("SELECT * FROM userdata") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $userid = $row['userid']; $username = $row['username']; // depends on what your field is called ?> <option value='<?=$userid?>"><?=$username?> <? } ?> </select> <br><br> <input type="submit" name="Submit" value="Submit"> </form> Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240068 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 I have jsut tried this but it does not output any information just a blank page Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240082 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 After slight adjustment to the code u gave me i have this put am so close but so far : </head> <body> <form name="form1" method="post" action="message1.php"> <select name="selectUser" size="1"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240084 Share on other sites More sharing options...
sanfly Posted April 27, 2007 Share Posted April 27, 2007 copy and post the code of the whole page please. And dont spam the thread please. Once you have posted give people a chance to look over things and post a reply Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240086 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 i copied the whole thread but it nt workin and how am i spamming please explain so i can correct me ways of posting Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240089 Share on other sites More sharing options...
per1os Posted April 27, 2007 Share Posted April 27, 2007 Let's consider this. Out of all the replies on this thread 8 are yours and 3 are someone elses. That is spamming. Use the Modify button if you need to add/change something within 5 minutes. Also use [ code ] tags bud. It makes it a lot easier to read through code. Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240094 Share on other sites More sharing options...
madspof Posted April 27, 2007 Author Share Posted April 27, 2007 okay i see ur point but if i dnt post another comment my post just gets moved back onto the other pages and is never seen again but okay i will stick to ur rule of dnt post anythink for 5 mins starting from this last post p.s i cannot et this dam code to work and ideas editied: I think my version of php will not acept the <? tage on it own it has to be <?php can u tell me a way of changing this Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240097 Share on other sites More sharing options...
per1os Posted April 27, 2007 Share Posted April 27, 2007 Only bump if a SIGNIFICANT amount of time has passed, or it IS on the second page. I have never seen this thread move off the front page and all of your other posts are within 5 minutes of each other. Believe me if someone has an answer for you it will be posted. But some people do not like helping other people who cannot read/obey the rules of posting here. I would highly suggest reading the rule thread and following that if you want timely help from people. They tend to help others who obey more than not. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php // Set the various database connect information. Host is usually // localhost. If no password, just leave blank. This information is // given by your web host OR if your own server, you setup yourself. // See php manual for setup instructions. $db_host = 'localhost'; $db_user = 'cms'; $db_pass = ''; $db_name = 'phpsms'; // More then one table can be used but in ths example we use just // one. :-) And in many scripts just one is used. And it's easiest // to comment on. $db_table = 'userdata'; // ---- END CONFIGURATIONS ------------------------------------------// // Make a connect to mysql. Through this connect many databases // and tables can be selected. $conn will be what we call this // connection. $conn = mysql_connect($db_host,$db_user,$db_pass); if ($conn) { // Select the database. mysql_select_db($db_name,$conn); $result = mysql_query("SELECT user_id from $db_table",$conn) OR DIE(mysql_error()); // incase that column name is wrong. while($row = mysql_fetch_object($result)) { $users[] = $row->userid; } // DEBUG STATEMENT FOR TESTING print_r($users); // Else we are not connected ($conn == false) so print error. } else { echo 'could not connect to database : '. mysql_error(); } // Print the pulled data. ?> <form name="form1" method="post" action="message1.php"> <p> <select name="select" size="1"> <option value="">Default</option> <?php if (isarray($users)) { foreach($users AS $user){ print '<option value=' . $user . '>' . $user . '</option>'; } } ?> </select> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> <p> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/49003-is-there-a-way-of-list-the-content-of-a-row-in-a-drop-down-list-arrays-maybye/#findComment-240100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.