Jump to content

[SOLVED] Page Ends when query is empty.


Lamez

Recommended Posts

Ok so I have a website's statistics page, and if one of the query is empty, it does not display any of the page. I am wondering how to fix this, here is the code:

 

<?php
$path = "";
$title = "Website's Statistics"; 
$rank = "yes";
$ban = "yes"; 
include ($path."main/include/cons/head.php");

$tot_usr = mysql_query("SELECT * FROM `users`")or die(mysql_error());
$tot_usr = mysql_num_rows($tot_usr)or die(mysql_error());

$banned = mysql_query("SELECT * FROM `users` WHERE `ban` = '1'")or die(mysql_error());
$banned = mysql_num_rows($banned)or die(mysql_error());

$admins = mysql_query("SELECT * FROM `users` WHERE `userlevel` = '9'") or die(mysql_error());
$admins = mysql_num_rows($admins)or die(mysql_error());

$members = mysql_query("SELECT * FROM `users` WHERE `userlevel` = '1'") or die(mysql_error());
$members = mysql_num_rows($members)or die(mysql_error());

$tot_pms = mysql_query("SELECT * FROM `messages` WHERE `id` >= 0") or die(mysql_error());
$tot_pms = mysql_num_rows($tot_pms) or die(mysql_error());

$un_pm = mysql_query("SELECT * FROM `messages` WHERE `recieved` = '0'")or die(mysql_error());
$un_pm = mysql_num_rows($un_pm) or die(mysql_error());

$re_pm = mysql_query("SELECT * FROM `messages` WHERE `recieved` = '1'")or die(mysql_error());
$re_pm = mysql_num_rows($re_pm) or die(mysql_error());

$top = mysql_query("SELECT * FROM `forum_question`")or die(mysql_error());
$top = mysql_num_rows($top) or die(mysql_error());

$res = mysql_query("SELECT * FROM `forum_answer`")or die(mysql_error());
$res = mysql_num_rows($res) or die(mysql_error());


echo'
<p class="header">Website\'s Statistics</p>
<p class="maintext">
<b>Total Users</b>: '.$tot_usr.'
<br />
<b>Total Banned Users</b>: '.$banned.'
<br />
<b>Total Admins</b>: '.$admins.'
<br />
<b>Total Members</b>: '.$members.'
<br /><br />
<b>Website Status</b>: '.$site_stat.'
<br /><br />
<b>Total PMs</b>: '.$tot_pms.'
<br />
<b>Total Unread PMs</b>: '.$un_pm.'
<br />
<b>Total Read PMs</b>: '.$re_pm.'
<br /><br />
<b>Total Forum Topics</b>: '.$top.'
<br />
<b>Total Forum Responses</b>: '.$res.'
</p>';


include ($path."main/include/cons/foot.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/125146-solved-page-ends-when-query-is-empty/
Share on other sites

try OR NULL on all the selects mate

 

example only

$banned = mysql_query("SELECT * FROM `users` WHERE `ban` = '1' OR NULL")or die(mysql_error());
$banned = mysql_num_rows($banned)or die(mysql_error());

 

maybe this is correct

 

$banned = mysql_query("SELECT * FROM `users` WHERE `ban` = '1' AND `ban`= NULL")or die(mysql_error());
$banned = mysql_num_rows($banned)or die(mysql_error());

yes this is the code I am using..

 

<?php
$path = "";
$title = "Website's Statistics"; 
$rank = "yes";
include ($path."main/include/cons/head.php");

$tot_usr = mysql_query("SELECT * FROM `users`")or NULL;
$tot_usr = mysql_num_rows($tot_usr)or NULL;

$banned = mysql_query("SELECT * FROM `users` WHERE `ban` = '1'")or NULL;
$banned = mysql_num_rows($banned)or NULL;

$admins = mysql_query("SELECT * FROM `users` WHERE `userlevel` = '9'") or NULL;
$admins = mysql_num_rows($admins)or NULL;

$members = mysql_query("SELECT * FROM `users` WHERE `userlevel` = '1'") or NULL;
$members = mysql_num_rows($members)or NULL;

$tot_pms = mysql_query("SELECT * FROM `messages` WHERE `id` >= 0") or NULL;
$tot_pms = mysql_num_rows($tot_pms) or NULL;

$un_pm = mysql_query("SELECT * FROM `messages` WHERE `recieved` = '0'")or NULL;
$un_pm = mysql_num_rows($un_pm) or NULL;

$re_pm = mysql_query("SELECT * FROM `messages` WHERE `recieved` = '1'")or NULL;
$re_pm = mysql_num_rows($re_pm) or NULL;

$top = mysql_query("SELECT * FROM `forum_question`")or NULL;
$top = mysql_num_rows($top) or NULL;

$res = mysql_query("SELECT * FROM `forum_answer`")or NULL;
$res = mysql_num_rows($res) or NULL;


echo'
<p class="header">Website\'s Statistics</p>
<p class="maintext">
<b>Total Users</b>: '.$tot_usr.'
<br />
<b>Total Banned Users</b>: '.$banned.'
<br />
<b>Total Admins</b>: '.$admins.'
<br />
<b>Total Members</b>: '.$members.'
<br /><br />
<b>Website Status</b>: '.$site_stat.'
<br /><br />
<b>Total PMs</b>: '.$tot_pms.'
<br />
<b>Total Unread PMs</b>: '.$un_pm.'
<br />
<b>Total Read PMs</b>: '.$re_pm.'
<br /><br />
<b>Total Forum Topics</b>: '.$top.'
<br />
<b>Total Forum Responses</b>: '.$res.'
</p>';


include ($path."main/include/cons/foot.php");
?>

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.