Shop error.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Random
Forum Commoner
Posts: 30
Joined: Wed Mar 12, 2003 5:38 pm

Shop error.

Post by Random »

Here is my shops.php script:

Code: Select all

<?php
ob_start();
session_start();

/*==============================*/
// Connect to the DB
/*==============================*/

$dbinfo = "random";

mysql_connect("localhost", $dbinfo, $dbinfo) or die( "Bad connection" );
mysql_select_db($dbinfo) or die( "Bad Database!" );

/*==============================*/
// Get the Info from the DB
// Count / Select Stuff
/*==============================*/

$query_count = "SELECT * FROM Shops WHERE ShopID = '$_GET['ShopID']'";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

/*==============================*/
// If there aren't any shops,
// display an error.
/*==============================*/

if ( $totalrows == 1) {
	print "Error: No shop with that ID.";
	exit();
}

/*==============================*/
// Hooray, a LOOP! *Excited*	
/*==============================*/

while( $r = mysql_fetch_array( $result_count ) ) {
	
	/*==========================*/
	// Info == Variables
	/*==========================*/
	
	$shopid = $r['ShopID'];
	$shopname = $r['ShopName'];
	$description = $r['ShopDesc'];
	
	/*==========================*/
	// Now the Results!
	/*==========================*/
	
	print "<TITLE>Dynopets - $shopname</TITLE>";
	print "Welcome to the <b>$shopname</b>, ".$_SESSION['username']."!";
}

/*==============================*/
// Here is where we will Select
// and count all of the items
// we just pulled from the data-
// base.  ASC or DESC, doesn't
// really matter.
/*==============================*/

$query_count2 = "SELECT * FROM ShopItems WHERE ShopID = '$shopid' ORDER BY ItemName ASC";
$result_count2 = mysql_query($query_count2);
$totalrows2 = mysql_num_rows($result_count2);

/*==============================*/
// If there are any errors just
// display this message
/*==============================*/

if ( $totalrows2 == 0 ) {
	print "<p align='center'><i>I am sorry</i> ".$_SESSION['username']."<i>, but we are sold out of everything!</i></p>\n\n";
	exit();
}

/*==============================*/
// Now to make the display of 
// the items pretty-like.
/*==============================*/

print "<p><table border='0' cellspacing='2' cellpadding='7'><tr>\n";
$cellamount = 0;

/*==============================*/
// Hooray, another LOOP!
/*==============================*/

while( $r = mysql_fetch_array($result_count2 ) ) {
	
	$itemid = $r['ID'];
	$itemshopname = $r['ShopName'];
	$itemname = $r['ItemName'];
	$itemdescription = $r['ItemDesc'];
	$itemimage = $r['Image'];
	$itemprice = $r['Price'];
	$itemamount = $r['Amount'];
	
	/*==========================*/
	// Display Each Item
	/*==========================*/
	print "<td align='center' width='125'><a onClick"return confirm('Are you sure you want to buy $itemname for $itemprice DynoBucks? (You will be able to Haggle on the next page!)');\ href='buyitem.php?ItemID=$itemid'>\n
	<img src="$itemimage" alt="$itemdescription" border='1' width='70' height='70'></a><br>\n
	<b>$itemname</b><br>$itemprice DynoBucks<br>$itemamount in stock</td>\n\n";
	
	/*==========================*/
	// This variable will make
	// it so we can keep track
	// of how many tds there
	// are before we reset.
	/*==========================*/
	
	$cellamount++;
	
	/*==========================*/
	// cell amount != 5
	/*==========================*/
	
	if ( $cellamount == 4 ) {
		
		print "</tr><tr>";
		
		/*======================*/
		// Reset cell amount 
		/*======================*/
		
		$cellamount = 0;
		
	}
	
}

/*==============================*/
// Now close this table and 
// all that other fun stuff.
/*==============================*/

print "</tr></table></center>";

?>
The problem I have is when I check my stock, it says Nothing is for sale, but there is supposed to be items. I even checked my Database. Any help will be appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you mean
print "<p align='center'><i>I am sorry</i> ".$_SESSION['username']."<i>, but we are sold out of everything!</i></p>\n\n";
is executed, i.e.
if ( $totalrows2 == 0 )
is true?
Post Reply