PDA

View Full Version : Problems with this query, all help appreciated.


-fedexer-
03-28-2008, 11:52 PM
//////////////////////////////////////////
$query = "SELECT * FROM serverlist WHERE serverOnline='1' and serverCompleted='1' and serverPriority='0'";
$result = mysql_query($query);
$rowAccountOnline = mysql_fetch_array($result) or die($query);
/////////////////////////////////////////////////

For some reason or another this query always dies, i know the column and db names are correct, so it must be the actual syntax i am using, but i don't know where it is going wrong.

All help appreciated.

-fedexer-
03-29-2008, 01:33 PM
i came across what my problem was, it was that the query was returning false, which then threw off the fetch_array, and so all i had to do was add a if statement to check that it wasn't false before creating the array.

God i feel dumb.

-fedexer-
03-29-2008, 06:49 PM
Well it seems i haven't come to a solution yet , even though i thought i had... here's my source code... the idea is to have a table fill with a list of servers that fit the criteria of the query's, but just now all i seem to get are errors thrown.

<?php
require_once("./connection/connect.php");
$debug = FALSE;
header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache");
session_start();


if (!isset($_SESSION['SESSION'])) require ( "./includes/sessions.php");


$flg = "";
$error = "";
if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"];

switch ($flg) {
case "red":
$error = "That username / password combination is not in our database.<br/> Note: Account information is case sensitive.<br/> Please Try Again.";

break;
case "blue":
$error = "Your Session has Expired.<br/> Please Login Again.";

break;
case "green":
$error = "<a href=\"./form.php?reason=banned\" >Your account has been banned.<br/> If you feel this was a mistake then please contact the admin via this form.</a>";
break;
case "orange":
$error = "You have attempted to log into a section, but it seems your session has expired.<br/> Please log back in to resolve this problem.";
break;
default:
$error = "";
}
$a = 1;
$b = 0;
//////////////////////////////////////////
$query = sprintf("SELECT * FROM serverlist WHERE serverOnline='1' AND serverCompleted='1' AND serverPriority='0'");
$resulta = mysql_query($query);
$rowAccountOnline = mysql_fetch_array($resulta) or die($query);
/////////////////////////////////////////////////
//////////////////////////////////////////
$query = sprintf("SELECT * FROM serverlist WHERE serverCompleted='1' AND serverOnline='0' AND serverPriority='0'");
$resultb = mysql_query($query);
$rowAccountOffline = mysql_fetch_array($resultb) or die($query);
/////////////////////////////////////////////////
//////////////////////////////////////////
$query = sprintf("SELECT * FROM serverlist WHERE serverCompleted='1' AND serverOnline='1' AND serverPriority='1'");
$resultc = mysql_query($query);
$rowAccountOnlineP = mysql_fetch_array($resultc) or die($query);
/////////////////////////////////////////////////
//////////////////////////////////////////
$query = sprintf("SELECT * FROM serverlist WHERE serverCompleted='1' AND serverOnline='0' AND serverPriority='1'");
$resultd = mysql_query($query);
$rowAccountOfflineP = mysql_fetch_array($resultd) or die($query);
/////////////////////////////////////////////////
//////////////////////////////////////////
$query = sprintf("SELECT * FROM serverlistglobal WHERE ID='1'");
$result = mysql_query($query);
$globalVars = mysql_fetch_array($result) or die($query);
/////////////////////////////////////////////////

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Server List</title>
<link href="./CSS/styleSheet.css" rel="stylesheet" type="text/css" media="screen,print" />
</head>
<body>
<div id="outside" class="outside">
<a name="top"></a>
<div id="inside" class="inside">
<div id="header" class="head">b</div>
<div id="nav_above" class="nav_above"></div>
<div id="nav" class="nav_bar">
<table width="100%" class="nav_bar_table" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><a href="index.php">Index</a></td>
<td align="center"><a href="register.php">Register</a></td>
<td align="center">Server List</td>
<td align="center">Top 10 Servers</td>
<td align="center">&nbsp;</td>
<td align="center"><a href="login.php">Login</a></td>
</tr>
</table>
</div>

<div id="content_holder" class="content_holder">
<div id="left" class="left"></div>
<div id="main_content" class="main_content">
<table width="100%" border="0" align="center" cellpadding="10" cellspacing="0">
<tr>
<td width="100%"><div align="center">Please login to view your server, add a server or edit your current server listing. <?php print_r($_SESSION); ?><br />
</div></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="10">
<tr <?php if($flg== "") { echo "class=\"formWarningsHide\""; } else { echo "class=\"\"";} ?>>
<td colspan="3"><div align="center" class="formWarnings"><?php if($flg != ""){echo $error; } ?></div></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="10">
<tr><td colspan="3" height="20"/></tr>
<tr><td class="tdhead" colspan="3" height="5"></td></tr>
<tr><td colspan="3"><strong>There are currently <?php echo $globalVars['serverCount'] ?> servers on this list.</strong></td>
</tr>
<tr>
<td height="5" colspan="3" class="tdhead"></td>
</tr>
<tr>
<td colspan="3" bordercolor="#F6F8FA" bgcolor="#FFFFFF"><strong>The official RaGEZONE server status is shown below:</strong></td>
</tr>
<tr><td height="20" colspan="3" class="tdhead"></td></tr>
<tr align="center" class="sticky">
<td><strong>Server Name</strong></td>
<td><strong>Server Status</strong></td>
<td><strong>Server Uptime (%)</strong></td>
</tr>
<tr><td height="5" class="tdhead" colspan="3"></td></tr>
<?php if($rowAccountOnlineP == true){ ?>
<?php do{ ?>
<tr align="center" <?php if($rowAccountOnlineP['serverOnline'] == 0){ echo "class=\"tdbodyhide\""; }else{ echo "class=\"tdbody\""; } ?> >
<td ><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnlineP['serverID'] ?>"><?php echo stripslashes($rowAccountOnlineP['serverName']); ?></a></td>
<td><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnlineP['serverID'] ?>"><?php if($rowAccountOnlineP['serverOnline'] == 1){ echo "Online"; } ?></a></td>
<td><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnlineP['serverID'] ?>"><?php echo $rowAccountOnlineP['serverUptime']; ?></a></td>
</tr>

<?php }while ($rowAccountOnlineP = mysql_fetch_array($resultc));?>
<?php } ?>
<?php if($rowAccountOfflineP == true){ ?>
<?php do{ ?>
<tr align="center" class="tdbody">
<td><a href="./serverinfo.php?serverID=<?php echo $rowAccountOfflineP['serverID'] ?>"><?php echo stripslashes($rowAccountOfflineP['serverName']); ?></a></td>
<td><a href="./serverinfo.php?serverID=<?php echo $rowAccountOfflineP['serverID'] ?>">
<?php if($rowAccountOfflineP['serverOnline'] == 0){ echo "Offline"; } ?>
</a></td>
<td><a href="./serverinfo.php?serverID=<?php echo $rowAccountOfflineP['serverID'] ?>"><?php echo $rowAccountOfflineP['serverUptime']; ?></a></td>
</tr>

<?php }while ($rowAccountOfflineP = mysql_fetch_array($resultd));?>
<?php } ?>
<tr><td colspan="3" height="10"><img src="images/spacer.gif" /></td></tr>
<tr><td colspan="3" height="10"><img src="images/spacer.gif" /></td></tr>
<tr><td height="5" class="tdhead" colspan="3"></td></tr>
<tr><td colspan="3"><strong>User Submitted Servers: </strong></td>
</tr>
<tr>
<td height="20" class="tdhead" colspan="3"></td>
</tr>
<tr align="center" class="sticky">
<td width="60%"><strong>Server Name</strong></td>
<td width="16%"><strong>Server Status</strong></td>
<td width="24%"><strong>Server Uptime (%)</strong></td>
</tr>
<tr>
<td height="5" class="tdhead" colspan="3"> </td>
</tr>
<?php if($rowAccountOnline == true){ ?>
<?php do{ ?>
<tr align="center" class="tdbody">
<td width="60%"><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnline['serverID'] ?>"><?php echo stripslashes($rowAccountOnline['serverName']); ?></a></td>
<td width="16%"><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnlineP['serverID'] ?>"><?php if($rowAccountOnline['serverOnline'] == 1){ echo "Online"; }else{ echo "Offline"; } ?></a></td>
<td width="24%"><a href="./serverinfo.php?serverID=<?php echo $rowAccountOnlineP['serverID'] ?>"><?php echo $rowAccountOnline['serverUptime']; ?></a></td>
</tr>
<?php }while ($rowAccountOnline = mysql_fetch_array($resulta)); ?>
<?php } ?>
<?php if($rowAccountOffline == true){ ?>
<?php do{ ?>
<tr align="center" class="tdbody">
<td width="60%"><?php echo stripslashes($rowAccountOffline['serverName']); ?></td>
<td width="16%"><?php echo "Offline"; ?></td>
<td width="24%"><?php echo $rowAccountOffline['serverUptime']; ?></td>
</tr>
<?php }while ($rowAccountOffline = mysql_fetch_array($resultb)); ?>
<?php } ?>
<tr><td colspan="3" height="10"><img src="images/spacer.gif" /></td></tr>
<tr><td colspan="3" height="10"><img src="images/spacer.gif" /></td></tr>
<tr><td height="5" class="tdhead" colspan="3"></td></tr>
<tr><td height="30" colspan="3"></td></tr>


<!--<tr align="center"><td colspan="3">The next server check will be in:</td></tr>-->
</table>
</div>
<div id="right" class="right"></div>
</div>



<div id="footer" class="footer">
<table align="right" class="footer_table" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="680" align="left"></td>
<td valign="middle"><div align="right">Contact Admin -</div></td>
<td valign="middle"><a href="#top">Top</a></td>
</tr>
</table>
</div>
<div id="bot" class="bottom"><table width="100%" class="bottom1" border="0" cellspacing="0" cellpadding="3"><tr><td valign="bottom" align="center"><a class="bottom1" href="http://forum.ragezone.com/members/-fedexer-/" target="_blank">A -fedexer- project for use by RaGEZONE Runescape Section</a></td>
</tr></table></div>
</div>
</div>
</body>
</html>

All of the fields being queried are int types, and they are named as they are in the DB.

-fedexer-
03-30-2008, 03:45 PM
Sorry bout this, anyway you may delete this thread now, i have finally figured the problem and found a solution.