Jump to content
MakeWebGames

Hospital


JamesRage

Recommended Posts

I just realized theres a slight error with the default hospital.php in MCCodes V1, the error appears on the page above the table as: Warning: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/*****/hospital.php on line 53

Code:

 

<?php
/*
MCCodes FREE
hospital.php Rev 1.1.0c
Copyright (C) 2005-2012 Dabomstew

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

session_start();
require "global_func.php";
if ($_SESSION['loggedin'] == 0)
{
   header("Location: login.php");
   exit;
}
$userid = $_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is =
       mysql_query(
               "SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",
               $c) or die(mysql_error());
$ir = mysql_fetch_array($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
print
       "<h3>Hospital</h3>
<table width='75%' border='2'><tr bgcolor=gray><th>ID</th><th>Name</th <th>Level</th> <th>Time</th><th>Reason</th></tr>";
$q =
       mysql_query(
               "SELECT u.*,c.* FROM users u WHERE u.hospital > 0 ORDER BY u.hospital DESC",
               $c);
while ($r = mysql_fetch_array($q))
{
   print
           "\n<tr><td>{$r['userid']}</td><td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td><td>
           {$r['level']}</td><td>{$r['hospital']} minutes</td><td>{$r['hospreason']}</td></tr>";
}
print "</table>";
$h->endpage();

 

Can't seem to figure out whats wrong, any suggestions please?

Link to comment
Share on other sites

after your initial $q query

if (mysql_num_rows(q))
{
//now continue on with the while() statement
}//don't forget to close the if()

or

while (!$q-> EOF)
{
   $r = mysql_fetch_array($q)
}

it may be returning false because no one is in the hospital. maybe you can try to put yourself in the hosp. and visit it and if it works add the code above

Edited by KyleMassacre
Link to comment
Share on other sites

<?php
session_start();
require "global_func.php";
if ($_SESSION['loggedin'] == 0)
{
   header("Location: login.php");
   exit;
}
$userid = $_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is = mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid", $c) or die(mysql_error());
$ir = mysql_fetch_array($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();


print "<h3>Hospital</h3>
<table width='75%' border='2'>
   <tr bgcolor=gray>
       <th>ID</th>
       <th>Name</th>
       <th>Level</th>
       <th>Time</th>
       <th>Reason</th>
   </tr>";
   $q = mysql_query("SELECT u.*,c.* FROM users u WHERE u.hospital > 0 ORDER BY u.hospital DESC", $c);
   if (mysql_num_rows($q) > 0)
   {
       while ($r = mysql_fetch_array($q))
       {
           print "
           <tr>
               <td>{$r['userid']}</td>
               <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td>
               <td>{$r['level']}</td>
               <td>{$r['hospital']} minutes</td>
               <td>{$r['hospreason']}</td>
           </tr>";
       }
   }
   else
   {
       echo "
       <tr>
           <td colspan='5'>There are currently no patients in the hospital.</td>
       </tr>";
   }
print "
</table>";
$h->endpage();
Link to comment
Share on other sites

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.   Paste as plain text instead

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