contra10 Posted February 5, 2009 Share Posted February 5, 2009 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143875-solved-simple-echo-from-mysql/ Share on other sites More sharing options...
pocobueno1388 Posted February 5, 2009 Share Posted February 5, 2009 Try to change your query to: $queryi = "SELECT DISTINCT(album) FROM `photoalbum` WHERE `userid` = '$idpic'"; Quote Link to comment https://forums.phpfreaks.com/topic/143875-solved-simple-echo-from-mysql/#findComment-754955 Share on other sites More sharing options...
contra10 Posted February 5, 2009 Author Share Posted February 5, 2009 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143875-solved-simple-echo-from-mysql/#findComment-754960 Share on other sites More sharing options...
pocobueno1388 Posted February 5, 2009 Share Posted February 5, 2009 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/143875-solved-simple-echo-from-mysql/#findComment-755035 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.