Jump to content

What to do if there are no values in the MS access database


smasroor

Recommended Posts

Hi Guys,

I am new to PHP programming. I am working for the past 18 hours to resolve a problem in PHP code with MS access database  :( but still there is no further progress.

 

Name of the Database: hd.mdb

Table Name: Staff

Field : UID

 

Now what I want is that whenever there is some value for the UID field in the database the php code should spit online on the web page and if the UID field in the database is blank than it should spit offline.

 

Below is the code which I wrote:

 

<?php

$conn=odbc_connect('hd','','');

if (!$conn)

{exit("Connection Failed: " . $conn);}

$sql="SELECT UID FROM Staff";

$rs=odbc_exec($conn,$sql);

if (!$rs)

{exit("Error in SQL");}

while (odbc_fetch_row($rs))

{

$UID=odbc_result($rs,"UID");

 

if(!$UID==0){

echo "Online";

}

else {

echo "Offline";

}

 

}

 

odbc_close($conn);

?>

 

 

Now this code is doing 50% of what I want. This code above do display "Online" when there is some record in UID field in the database(which is I want) but if there is no record in the database then instead of displaying offline it does not display anything.

 

I look forward for help from your side in resolving this error.

 

Thanks and let me know if any of you wants me to provide any more information that this.

You'll want to check odbc_num_rows.

 

While you at it, being new to programming (not trying to have a dig at you) you should start out without bad habits. Your indentation and code formatting is terrible. Have you really seen example code that is that hard to read?

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.