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); ?> Link to comment https://forums.phpfreaks.com/topic/256648-how-to-retrieve-very-first-record-in-database-using-odbc/ 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? Link to comment https://forums.phpfreaks.com/topic/256648-how-to-retrieve-very-first-record-in-database-using-odbc/#findComment-1315668 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. Link to comment https://forums.phpfreaks.com/topic/256648-how-to-retrieve-very-first-record-in-database-using-odbc/#findComment-1315669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.