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 Quote Link to comment Share on other sites More sharing options...
Mr P!nk Posted November 7, 2007 Author Share Posted November 7, 2007 Bump. anyone? Quote Link to comment 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>"; Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 can you post your changed code Quote Link to comment 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 Quote Link to comment 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>"; Quote Link to comment 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 Quote Link to comment 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.