Mr P!nk Posted November 6, 2007 Share Posted November 6, 2007 im having a problem printing results from my database to a drop down list. this is the insert into database witch works fine. <?php include 'db.php'; $sql = mysql_query("SELECT * FROM list WHERE list_name='$list_name'"); $list_check = mysql_num_rows($sql); if(($list_check > 0)){ echo "The name $list_name is already being used."; unset($list_name,$list_content); } else{ $sql = "insert into * (list_name,list_content) values ('$list_name', '$list_content')"; $result = mysql_query($sql); echo "$list_name has been uploaded."; } ?> but here i want it to show the results in a list so the user can select one and the contents will be placed into a text area <form id="form1" action"edit.php?action=listname" name"form1" method="post"> <label>List</label><br /> <?php $sql = "select list_name,list_content from list order by id DESC"; $query = mysql_query($sql); $result = mysql_fetch_array($query); do{ printf("<select name=\"list\" size=\"5\" multiple=\"multiple\" id=\"list\"> <option>Please Select a database</option> <option>%s</option> </select>",$result['list_name'], $result['id'], $result['list_content']); } while($result = mysql_fetch_array($query)); ?> <input type="submit" name="Submit" value="Submit" /> </form> <br /> <br /> Mailing List<br /> <label> <textarea name="list_content" cols="50" rows="3" class="formData" id="list_content"> <?php if ( $action == 'listname') {printf("email_list"); } ?> </textarea> so far it prints a list for every value in the database, i need them all to just go into one, and when the user presses submit the contents of their selected list goes into the text area. any ideas of how i would accomplish this task ? Many thanks P!nk Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/ Share on other sites More sharing options...
Mr P!nk Posted November 7, 2007 Author Share Posted November 7, 2007 Bump. anyone? Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386577 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 try this for your select echo "<select name=\"list\" size=\"5\" multiple=\"multiple\" id=\"list\">"; echo "<option>Please Select a database</option>"; while($result = mysql_fetch_array($query)) { echo "<option value='{$result['id']}'>{$result['list_name']}</option>"; } echo "</select>"; Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386579 Share on other sites More sharing options...
Mr P!nk Posted November 7, 2007 Author Share Posted November 7, 2007 Thanks for your help rajivgonsalves but using that i get thrown this error : Parse error: parse error, unexpected $ in /public_html/mercury/edit.php on line 461 ive checked the code for any missing {}();" ' but all looks in place ;/ any ideas? Thanks again Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386635 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 can you post your changed code Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386636 Share on other sites More sharing options...
Mr P!nk Posted November 7, 2007 Author Share Posted November 7, 2007 sure <?php $sql = "select list_name,list_content from list order by id DESC"; $query = mysql_query($sql); $result = mysql_fetch_array($query); do{ echo "<select name=\"list\" size=\"5\" multiple=\"multiple\" id=\"list\">"; echo "(<option>Please Select a database</option>)"; while($result = mysql_fetch_array($query)) { echo "<option value='{$result['id']}'>{$result['list_name']}</option>"; } echo "</select>"; when i close the do{ i get errors Parse error: parse error, unexpected ';', expecting T_WHILE in /home/acmeart/public_html/mercury/tabloid.php on line 143 Thanks Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386642 Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 well you do not require the do try this code (modified) <?php $sql = "select list_name,list_content from list order by id DESC"; $query = mysql_query($sql); $result = mysql_fetch_array($query); echo "<select name=\"list\" size=\"5\" multiple=\"multiple\" id=\"list\">"; echo "(<option>Please Select a database</option>)"; while($result = mysql_fetch_array($query)) { echo "<option value='{$result['list_name']}'>{$result['list_name']}</option>"; } echo "</select>"; Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386645 Share on other sites More sharing options...
Mr P!nk Posted November 7, 2007 Author Share Posted November 7, 2007 haha yes i done that straight after i posted thank you for your help rajivgonsalves Topic Solved Link to comment https://forums.phpfreaks.com/topic/76248-solved-mysql-printf-to-a-list/#findComment-386650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.