Jump to content

[SOLVED] mysql printf to a list.


Mr P!nk

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.