Jump to content

if question


techker

Recommended Posts

well ok..

 

my querry:

$query9 = "SELECT COUNT(*) AS TotalCount, `to_t1` - `from_t1` + `to_t2` - `from_t2`+ `to_t3` - `from_t3`+ `to_t4` - `from_t4`+ `to_t5` - `from_t5`+`to_t6` - `from_t6`+ `to_t7` - `from_t7` AS TotalNumber, SUM( `to_t1` - `from_t1` + `to_t2` - `from_t2`+ `to_t3` - `from_t3`+ `to_t4` - `from_t4`+ `to_t5` - `from_t5`+`to_t6` - `from_t6`+ `to_t7` - `from_t7`) AS Totalhours FROM `week1`GROUP BY `from_t1` "; 
$result9 = mysql_query($query9) or die(mysql_error());

 

when when my db is empty it shows nothing.now i want it so when it is empty it shows off

Link to comment
Share on other sites

if (mysql_affected_rows == 0) {
echo "Off";
} else {
//parse reults from $result9
}

 

 

Ok... but your query will always return (at least) one row. So:

 

$query9 = "SELECT COUNT(*) AS TotalCount, `to_t1` - `from_t1` + `to_t2` - `from_t2`+ `to_t3` - `from_t3`+ `to_t4` - `from_t4`+ `to_t5` - `from_t5`+`to_t6` - `from_t6`+ `to_t7` - `from_t7` AS TotalNumber, SUM( `to_t1` - `from_t1` + `to_t2` - `from_t2`+ `to_t3` - `from_t3`+ `to_t4` - `from_t4`+ `to_t5` - `from_t5`+`to_t6` - `from_t6`+ `to_t7` - `from_t7`) AS Totalhours FROM `week1`GROUP BY `from_t1` "; 
$result9 = mysql_query($query9) or die(mysql_error());
$row = mysql_fetch_array($result9);
if ($row['TotalCount'] == 0) {
echo "off";
} else {
//
}

Link to comment
Share on other sites

ok small question for me to understand once and for all!lolsorry

 

that querry is in the top of my page.now in my page were the echo is i put this

<?  while($row = mysql_fetch_array($result9)) {?>

<? echo $row['Totalhours'] ." H"; ?>

<? }?>

now do i put that if there?
<?  while($row = mysql_fetch_array($result9)) {?>

if (mysql_affected_rows == 0) {
echo "Off";
} else {
<? echo $row['Totalhours'] ." H"; ?>
}

 

 

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.