Jump to content

[SOLVED] simple echo from mysql


contra10

Recommended Posts

I want to echo the input from my mysql but only one of each album name...ie if there is 4 "Dogs" and 3 "Cats" it only echoes 1"Dog" and 1"Cat"

 

<?php
$queryi = "SELECT * FROM `photoalbum` WHERE `userid` = '$idpic'";
$resulti = mysql_query($queryi);
while($rowid = mysql_fetch_assoc($resulti))
{
$iduu= "{$rowid['album']}";

echo"<option value='$iduu'>$iduu</option>"; 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/143875-solved-simple-echo-from-mysql/
Share on other sites

it worked but do u know why only the first one is being echoed in the select option and the rest are outside?

<?php echo "<select type='Submit' name='album' disabled>"; 

mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("userimages") or die(mysql_error());

$queryi = "SELECT DISTINCT(album) FROM `photoalbum` WHERE `username` = '$usernamecookie'";
$resulti = mysql_query($queryi);
while($rowid = mysql_fetch_array($resulti))
{
$iduu= "{$rowid['album']}";

echo"<option value='$iduu'>$iduu</option>"; 
echo"</select>";
}

?>

Because you are closing your select inside the loop.

 

Change your while loop to this:

 

   while($rowid = mysql_fetch_array($resulti))
   {
$iduu= "{$rowid['album']}";

echo"<option value='$iduu'>$iduu</option>"; 
   }

echo"</select>";

Archived

This topic is now archived and is closed to further replies.

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