Jump to content

Recommended Posts

What I want to do is add a part to the if statement that if there isn't a record present in the database then it displays "There are no open weekly events.". How do I do this?

 

$query = "SELECT * FROM events ORDER BY `showname`";
$result = mysql_query ( $query ); // Run The Query
if ($result) 
{
	// Fetch and print all records.
	$i = 0;
	while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) 
	{
		$sClass = 'row2';
		if ($i ++ & 1) 
		{
			$sClass = 'row1';
		}
		printf ( "<tr class=\"%s\">", $sClass );
		print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editbooker('editbooker', 'content' , '". $row ['showname'] ."'); return false;\">Edit</a></td>";
		printf ( "<td valign=\"top\">%s</td>", $row [showname] );
		printf ( "<td align=\"center\" width=\"80\">%s</td>", $row [airs] );
		printf ( "<td align=\"center\" width=\"50\">%s</td>", $row [matches] );
		printf ( "<td align=\"center\" width=\"100\">%s</td>", $row [status] );
		print '</tr>';
	}
}

Link to comment
https://forums.phpfreaks.com/topic/144364-adding-else-to-if-statement/
Share on other sites

so it should be:

 

$query = "SELECT * FROM events WHERE `type` = 'Pay Per View' ORDER BY `showname`";
$result = mysql_query ( $query ); // Run The Query
if ($result) 
{
	// Fetch and print all records.
	$i = 0;
	while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) 
	{
		$sClass = 'row2';
		if ($i ++ & 1) 
		{
			$sClass = 'row1';
		}
		printf ( "<tr class=\"%s\">", $sClass );
		print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editbooker('editbooker', 'content' , '". $row ['showname'] ."'); return false;\">Edit</a></td>";
		printf ( "<td valign=\"top\">%s</td>", $row [showname] );
		printf ( "<td align=\"center\" width=\"80\">%s</td>", $row [airs] );
		printf ( "<td align=\"center\" width=\"50\">%s</td>", $row [matches] );
		printf ( "<td align=\"center\" width=\"100\">%s</td>", $row [status] );
		print '</tr>';
	}
if ($rows > 0) 
{

}else {
   echo 'No rows to display.';
}
}

so it should be:

umm no...did you not read how I wrote it?

 

$query = "SELECT * FROM events WHERE `type` = 'Pay Per View' ORDER BY `showname`";
    $result = mysql_query ( $query ); // Run The Query
    $rows = mysql_num_rows($result);
    if ($rows > 0) 
{
	// Fetch and print all records.
	$i = 0;
	while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) 
	{
		$sClass = 'row2';
		if ($i ++ & 1) 
		{
			$sClass = 'row1';
		}
		printf ( "<tr class=\"%s\">", $sClass );
		print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editbooker('editbooker', 'content' , '". $row ['showname'] ."'); return false;\">Edit</a></td>";
		printf ( "<td valign=\"top\">%s</td>", $row [showname] );
		printf ( "<td align=\"center\" width=\"80\">%s</td>", $row [airs] );
		printf ( "<td align=\"center\" width=\"50\">%s</td>", $row [matches] );
		printf ( "<td align=\"center\" width=\"100\">%s</td>", $row [status] );
		print '</tr>';
	}
}else {
    echo 'No rows to display.';
}

 

This is what it should be and I have also included the full function when it displays the message if there is no rows then there shouldn't even be a table either:

 

help.jpg

 

function booker() 
{
print '<script language="JavaScript" src="ts_picker.js"></script>';
print '<h1 class="backstage">Event Booking Management</h1><br />';
print "<h2 class=\"backstage\">Weekly Events :: <a href=\"#\" onclick=\"ajaxpage('booklineup', 'content'); return false;\">Book Lineup</a></h2>";
print '<br />There are no open weekly events.<br /><br />';
print "<h2 class=\"backstage\">PPV Events :: <a href=\"#\" onclick=\"ajaxpage('booklineup', 'content'); return false;\">Book Lineup</a></h2><br />";
print '<table width="100%" class="table1">';
print '<tr class="rowheading">';
print '<td align="center" border="0" width="1"> </td>';
print '<td>Show Name</td>';
print '<td width="80" align="center">Airs</td>';
print '<td width="50" align="center">Matches</td>';
print '<td width="100" align="center">Status</td>';
print '</tr>';
$query = "SELECT * FROM events WHERE `type` = 'Pay Per View' ORDER BY `showname`";
    $result = mysql_query ( $query ); // Run The Query
    $rows = mysql_num_rows($result);
    if ($rows > 0) 
{
// Fetch and print all records.
	$i = 0;
	while ( $row = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) 
	{
	$sClass = 'row2';
	if ($i ++ & 1) 
		{
		$sClass = 'row1';
		}
	printf ( "<tr class=\"%s\">", $sClass );
	print "<td valign=\"top\" align=\"center\" width=\"30\"><a href=\"#\" onclick=\"editbooker('editbooker', 'content' , '". $row ['showname'] ."'); return false;\">Edit</a></td>";
	printf ( "<td valign=\"top\">%s</td>", $row [showname] );
	printf ( "<td align=\"center\" width=\"80\">%s</td>", $row [airs] );
	printf ( "<td align=\"center\" width=\"50\">%s</td>", $row [matches] );
	printf ( "<td align=\"center\" width=\"100\">%s</td>", $row [status] );
	print '</tr>';
	}
}else 
{
    print '<br /><span>There are no open weekly events.</span><br /><br />';
}
print '</table><br />';
print '<h2 class="backstage"><input type="button" value="Return to Main Menu" class="button200"></form></h2>';
}

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.