Jump to content

how to retrieve very first record in database using ODBC


kdawg2k12

Recommended Posts

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.