Ameslee Posted November 27, 2006 Share Posted November 27, 2006 hope someone can help me. Im trying to display data from database on to my website. It displays the first record only. Why its meant to show at least 7. why isnt it working?here is the code:[code] <?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("", $conn); $query = "SELECT * FROM events WHERE Date >=now() ORDER BY Date ASC"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); echo "<table border=0 cellpadding=0 cellspacing=0>"; $i=1; while (($row!="") && ($i<=7)) { $date=$row[2]; $day=substr($date,8,2); $month=substr($date,5,2); $year=substr($date,0,4); $date2=$day." - ".$month." - ".$year; $event = $row[1]; echo("<tr><td width=35%>$event</td><td width=25%>$date2</td></tr> "); $row=mysql_fetch_row($mysql_result); $i++; } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/ Share on other sites More sharing options...
fert Posted November 27, 2006 Share Posted November 27, 2006 what happens when you run the script? Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-130855 Share on other sites More sharing options...
fiddy Posted November 27, 2006 Share Posted November 27, 2006 try $row=mysql_fetch_array($mysql_result); instead of $row=mysql_fetch_row($mysql_result); Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-130862 Share on other sites More sharing options...
Ameslee Posted November 28, 2006 Author Share Posted November 28, 2006 ok i have changed the $row=mysql_fetch_array($mysql_result); instead of $row=mysql_fetch_row($mysql_result);it is still doing the same thing, only displays one record. Here is the code again with the change and also the table, maybe it has something to do with where it is positioned. Its a table within another table.[code]<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php $hostname = localhost; $username = greenac_Admin; $password = greenac; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM events WHERE Date >=now() ORDER BY Date ASC"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_array($mysql_result); echo "<table border=0 cellpadding=0 cellspacing=0>"; $i=1; while (($row!="") && ($i<=7)) { $date=$row[2]; $day=substr($date,8,2); $month=substr($date,5,2); $year=substr($date,0,4); $date2=$day." - ".$month." - ".$year; $event = $row[1]; echo("<tr><td width=35%>$event</td><td width=25%>$date2</td></tr> "); $row=mysql_fetch_array($mysql_result); $i++; } ?> </td> </tr> <tr> <td><font size="2" face="Georgia, Times New Roman, Times, serif"><a href="display_events.php">Click here to view all events and details!</a> </font></td> </tr> </table>[/code] Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131242 Share on other sites More sharing options...
fiddy Posted November 28, 2006 Share Posted November 28, 2006 Pls try like this1. i have removed $row=mysql_fetch_array($mysql_result) which is after mysql_query2. i have replaced $row!="" with $row=mysql_fetch_array($mysql_result) in while3 removed $row=mysql_fetch_array($mysql_result) which comes after echo I am not sure this will work. But give a try . And i hope your database has more than one record and the query $query = "SELECT * FROM events WHERE Date >=now() ORDER BY Date ASC"; results in more than one record.<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php $hostname = localhost; $username = greenac_Admin; $password = greenac; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM events WHERE Date >=now() ORDER BY Date ASC"; $mysql_result=mysql_query($query,$conn); echo "<table border=0 cellpadding=0 cellspacing=0>"; $i=1; while (($row=mysql_fetch_array($mysql_result)) && ($i<=7)) { $date=$row[2]; $day=substr($date,8,2); $month=substr($date,5,2); $year=substr($date,0,4); $date2=$day." - ".$month." - ".$year; $event = $row[1]; echo("<tr><td width=35%>$event</td><td width=25%>$date2</td></tr> "); $i++; } ?> </td> </tr> <tr> <td><font size="2" face="Georgia, Times New Roman, Times, serif"><a href="display_events.php">Click here to view all events and details!</a> </font></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131376 Share on other sites More sharing options...
Ameslee Posted November 28, 2006 Author Share Posted November 28, 2006 na still one record displaying :-[ why? Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131382 Share on other sites More sharing options...
corbin Posted November 28, 2006 Share Posted November 28, 2006 Are you sure it should be WHERE Date >now() and not <? Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131383 Share on other sites More sharing options...
fiddy Posted November 28, 2006 Share Posted November 28, 2006 Pls check your query direcly(phpmyadmin) and see how many records you get in result Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131386 Share on other sites More sharing options...
Ameslee Posted November 28, 2006 Author Share Posted November 28, 2006 i have at least 5 other records in there already, i check phpmyadmin and there are 5.[quote]Are you sure it should be WHERE Date >now() and not <?[/quote] if i was to do this it would make it less than the present date to be displayed. Now that i have read that, i am soo stupid. Ok i am sure i have it now. thanks u guys! Link to comment https://forums.phpfreaks.com/topic/28602-help-with-displaying-from-database/#findComment-131390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.