adamjones Posted September 22, 2009 Share Posted September 22, 2009 Hi. I'm making a simple badge notification system, so when a user is given a badge, they are alerted. This is my code; <?php $host="localhost"; $username=""; $password=""; $db_name=""; $tbl_name="badgealerts"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE username='".$_SESSION['user']."'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); echo "".$rows['alert'].""; $sql2="DELETE FROM $tbl_name WHERE username='".$_SESSION['user']."'"; $result2 = @mysql_query($sql2); ?> And this is how my database looks; However, it is only echoing one, no matter how many entries I have? :/ Cheers. Link to comment https://forums.phpfreaks.com/topic/175160-solved-dont-understand-what-im-doing-wrong-on-this/ Share on other sites More sharing options...
KevinM1 Posted September 22, 2009 Share Posted September 22, 2009 You need to loop through your results when you use a SELECT query: while ($row = mysql_fetch_assoc($result)) { // do stuff } Without looping, you only get the first row. Link to comment https://forums.phpfreaks.com/topic/175160-solved-dont-understand-what-im-doing-wrong-on-this/#findComment-923185 Share on other sites More sharing options...
adamjones Posted September 22, 2009 Author Share Posted September 22, 2009 You need to loop through your results when you use a SELECT query: while ($row = mysql_fetch_assoc($result)) { // do stuff } Without looping, you only get the first row. Cheers! Link to comment https://forums.phpfreaks.com/topic/175160-solved-dont-understand-what-im-doing-wrong-on-this/#findComment-923187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.