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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.