kdawg2k12 Posted February 8, 2012 Share Posted February 8, 2012 CAN ANYONE TELL ME WHAT i AM DOING WRONG. I WANT TO RETRIEVE THE VERY FIRST RECORD IN MY DATABASE WHEN THE CODE EXECUTE IT ONLY SHOWS THE LAST RECORD IN THE DATABASE <?PHP $thisMonth = date('M'); $thisDay = date('j'); $eventMonth = array(); $eventDay = array(); $eventTime = array(); $eventName = array(); $eventLocation = array(); $dbMonth=""; $dbDay=""; $i=0; $conn = odbc_connect('eventsDB','',''); $sql= "SELECT month,day, time, event,location FROM Events"; $rs="$conn,$sql"; if (!$conn) { exit("Connection Failed: " . $conn); } $rs=odbc_exec($conn,$sql); if(!$rs) { exit("Error in SQL"); } echo "DATABASE OPEN"; while($i<3) { $dbMonth= odbc_result($rs,"month"); echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; if($dbMonth<>$thisMonth) { odbc_fetch_row($rs); } echo $eventMonth[$i]=odbc_result($rs,"month")."\n"; echo $eventDay[$i]=odbc_result($rs,"day")."\n"; echo $eventTime[$i]=odbc_result($rs,"time")."\n"; echo $eventDay[$i]=odbc_result($rs,"event")."\n"; echo $eventLocation[$i]=odbc_result($rs,"location")."\n"; $i++; odbc_fetch_row($rs); echo $i; } //ends while loop odbc_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 8, 2012 Share Posted February 8, 2012 Do you not have any auto increment field like `id` in your table? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted February 8, 2012 Share Posted February 8, 2012 $sql= "SELECT month,day, time, event,location FROM Events ORDER BY Primary_Key ASC LIMIT 1"; // ORDER BY `id` or whatever in ascending order. Limit to one result only. Quote Link to comment 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.