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
https://forums.phpfreaks.com/topic/122415-if-question/#findComment-632594
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
https://forums.phpfreaks.com/topic/122415-if-question/#findComment-632598
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
https://forums.phpfreaks.com/topic/122415-if-question/#findComment-632607
Share on other sites

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.