Jump to content

[SOLVED] Messages not displaying


twilitegxa

Recommended Posts

I have a page that displays my records in my table according to if the field "available" is set to "0". If no records have that value, each table (scouts, knights, fdark_warrior, and mdark_warrior) is suppsoed to display a message (ie. No Scouts exist, No Knights exist, No Female Dark Warriors exist, and No Male Dark Warriors exist), but when all records are set to "0", only the last two messages display (No Female Dark Warriors exist, and No Male Dark Warriors exist). How can I fix the code so that my other two messages display as well (No Scouts exist and No Knights exist)? Here is my code:

 

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "listcharacters.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php
//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//gather the scouts
$get_topics = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_scout_create_time,
username, available from scouts where available = '0' order by create_time desc";
$get_topics_res = mysql_query($get_topics, $conn) or die(mysql_error());
if (mysql_num_rows($get_topics_res) < 1) {
//there are no topics, so say so
$display_block = "<p><em>No Scouts exist.</em></p>";
} else {
//get number of players
$get_num_posts = "select count(id) from scouts";
	$get_num_posts_res = mysql_query($get_num_posts, $conn)
		or die(mysql_error());
	$num_posts = mysql_result($get_num_posts_res, 0, 'count(id)');

//create the display string
$display_block = "
<table cellpadding=4 cellspacing=2 border=1>
<tr>
<th>SCOUTS</th>
<th># OF PLAYERS: $num_posts</th>
</tr>";

while ($topic_info = mysql_fetch_array($get_topics_res)) {
	$topic_id = $topic_info['id'];
	$topic_title = ucwords(strtolower($topic_info['identity']));
	$topic_create_time = $topic_info['fmt_scout_create_time'];
	$topic_owner = $topic_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_scouts.php?id=$topic_id\">
		<strong>$topic_title</strong></a><br>
		<em>Created on $topic_create_time by</em> <strong>$topic_owner</strong></td>
		<td align=center> </td>
		</tr>";
	}
}

//gather the knights
$get_knights = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_knight_create_time,
username, available from knights where available = '0' order by create_time desc";
$get_knights_res = mysql_query($get_knights, $conn) or die(mysql_error());
if (mysql_num_rows($get_knights_res) < 1) {
//there are no knights, so say so
$display_block = "<p><em>No Knights exist.</em></p>";
} else {
//get number of players
$get_num_knights = "select count(id) from knights";
	$get_num_knights_res = mysql_query($get_num_knights, $conn)
		or die(mysql_error());
	$num_knights= mysql_result($get_num_knights_res, 0, 'count(id)');

//create the display string
$display_block .= "
<tr>
<th>KNIGHTS</th>
<th># OF PLAYERS: $num_knights</th>
</tr>";

while ($knight_info = mysql_fetch_array($get_knights_res)) {
	$knight_id = $knight_info['id'];
	$knight_identity = ucwords(strtolower($knight_info['identity']));
	$knight_create_time = $knight_info['fmt_knight_create_time'];
	$knight_username = $knight_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_knights.php?id=$knight_id\">
		<strong>$knight_identity</strong></a><br>
		<em>Created on $knight_create_time by</em> <strong>$knight_username</strong></td>
		<td align=center> </td>
		</tr>";
	}
}

//gather the fdark_warriors
$get_fdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_fdark_warrior_create_time,
username, available from fdark_warrior where available = '0' order by create_time desc";
$get_fdark_warriors_res = mysql_query($get_fdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_fdark_warriors_res) < 1) {
//there are no female dark warriors, so say so
$display_block = "<p><em>No Female Dark Warriors exist.</em></p>";
} else {
//get number of players
$get_num_fdark_warriors = "select count(id) from fdark_warrior";
	$get_num_fdark_warriors_res = mysql_query($get_num_fdark_warriors, $conn)
		or die(mysql_error());
	$num_fdark_warriors = mysql_result($get_num_fdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "
<tr>
<th>FEMALE DARK WARRIORS</th>
<th># OF PLAYERS: $num_fdark_warriors</th>
</tr>";

while ($fdark_warrior_info = mysql_fetch_array($get_fdark_warriors_res)) {
	$fdark_warrior_id= $fdark_warrior_info['id'];
	$fdark_warrior_identity = ucwords(strtolower($fdark_warrior_info['identity']));
	$fdark_warrior_create_time = $fdark_warrior_info['fmt_fdark_warrior_create_time'];
	$fdark_warrior_username = $fdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_fdark_warrior.php?id=$fdark_warrior_id\">
		<strong>$fdark_warrior_identity</strong></a><br>
		<em>Created on $fdark_warrior_create_time by</em> <strong>$fdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr>";
	}
}	

//gather the male dark_warriors
$get_mdark_warriors = "select id, identity,
date_format(create_time, '%b %e %Y at %r') as fmt_mdark_warrior_create_time,
username, available from mdark_warrior where available = '0' order by create_time desc";
$get_mdark_warriors_res = mysql_query($get_mdark_warriors, $conn) or die(mysql_error());
if (mysql_num_rows($get_mdark_warriors_res) < 1) {
//there are no male dark warriors, so say so
$display_block .= "<p><em>No Male Dark Warriors exist.</em></p>";
} else {
//get number of players
$get_num_mdark_warriors = "select count(id) from mdark_warrior";
	$get_num_mdark_warriors_res = mysql_query($get_num_mdark_warriors, $conn)
		or die(mysql_error());
	$num_mdark_warriors = mysql_result($get_num_mdark_warriors_res, 0, 'count(id)');

//create the display string
$display_block .= "
<tr>
<th>MALE DARK WARRIORS</th>
<th># OF PLAYERS: $num_mdark_warriors</th>
</tr>";

while ($mdark_warrior_info = mysql_fetch_array($get_mdark_warriors_res)) {
	$mdark_warrior_id= $mdark_warrior_info['id'];
	$mdark_warrior_identity = ucwords(strtolower($mdark_warrior_info['identity']));
	$mdark_warrior_create_time = $mdark_warrior_info['fmt_mdark_warrior_create_time'];
	$mdark_warrior_username = $mdark_warrior_info['username'];

	//add to display
	$display_block .= "
	<tr>
	<td><a href=\"showprofile_mdark_warrior.php?id=$mdark_warrior_id\">
		<strong>$mdark_warrior_identity</strong></a><br>
		<em>Created on $mdark_warrior_create_time by</em> <strong>$mdark_warrior_username</strong></td>
		<td align=center> </td>
		</tr>";
	}
}	

	//close up the table
	$display_block .= "</table>";
?>
<html>
<head>
<title>Sailor Moon RPG - Characters</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Characters In Sailor Moon RPG</h1>
<h3>Would you like to <a href="creationform.php">create a character</a>?</h3>
<?php print $display_block; ?>
</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

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.