Page 1 of 1

Retrieving Database contents

Posted: Sat Apr 28, 2012 6:53 pm
by abbey4biz
Please i will like you to help me out with these codings. I tried retrieving data from the database through the url in the side.php file and using the function, 'products()' in the cart.php file. It worked on my local server, but not working fine on the remote server.

Please kindly help me in checking out the codings.
Thanks.

The below is the side.php file

Code: Select all

<li class="color"><a href="<?php echo "m_category.php?product='agric'"; ?>">Agriculture</a></li>
				<li><a href="<?php echo "m_category.php?product='apparel'"; ?>">Apparel</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='auto'"; ?>">Automobiles & Motorcycles</a></li>
				<li><a href="<?php echo "m_category.php?product='chemicals'"; ?>">Chemicals</a></li>
				<li class="color"><a href=<?php echo "m_category.php?product='computer'"; ?> >Computer Hardware & Software</a></li>
				<li><a href="<?php echo "m_category.php?product='real_estate'"; ?>">Construction & Real Estate</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='consumer_elect'"; ?>">Consumer Electronics</a></li>
				<li><a href="<?php echo "m_category.php?product='electrical'"; ?>">Electrical Equipment</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='fashion'"; ?>">Fashion Accessories</a></li>
				<li><a href="<?php echo "m_category.php?product='food'"; ?>">Food & Beverage</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='furniture'"; ?>">Furniture</a></li>
				<li><a href="<?php echo "m_category.php?product='gifts'"; ?>">Gifts & Crafts</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='health'"; ?>">Health & Medical</a></li>
				<li><a href="<?php echo "m_category.php?product='home_appliance'"; ?>">Home Appliances</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='hotels'"; ?>">Hotels</a></li>
				<li><a href="<?php echo "m_category.php?product='lights'"; ?>">Lights & Lighting</a></li>
				<li  class="color"><a href="<?php echo "m_category.php?product='machinery'"; ?>">Machinery</a></li>
				<li><a href="<?php echo "m_category.php?product='mechanical'"; ?>">Mechanical Parts </a></li>
				<li  class="color"><a href="<?php echo "m_category.php?product='office'"; ?>">Office & School Supplies</a></li>
				<li><a href="<?php echo "m_category.php?product='packaging'"; ?>">Packaging & Printing</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='shoes'"; ?>">Shoes & Accessories</a></li>
				<li><a href="<?php echo "m_category.php?product='sports'"; ?>">Sports & Entertainment</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='textiles'"; ?>">Textiles & Leather Products</a></li>
				<li><a href="<?php echo "m_category.php?product='toys'"; ?>">Toys & Hobbies</a></li>
				<li class="color"><a href="<?php echo "m_category.php?product='transport'"; ?>">Transportation</a></li>
				<li><a href="<?php echo "m_category.php?product='tools'"; ?>">Tools</a></li>

Below is the product display function

Code: Select all

function products(){

require_once ('dbc1.php');

// Number of records to show per page:

$display = 10;

// Determine how many pages there are...

if (isset($_GET['p']) && is_numeric($_GET ['p'])) { // Already been determined.

$pages = $_GET['p'];

} else { // Need to determine.

// Count the number of records:

if (isset($_GET['product'])){

$product = ($_GET['product']);
}

?>

<title>The MarketPlace</title>

<?php

$q = "SELECT COUNT(id) FROM products WHERE category = $product ";
$r = @mysqli_query ($dbc, $q);
$row = @mysqli_fetch_array ($r, MYSQLI_NUM);

$records = $row[0];

// Calculate the number of pages...


if ($records > $display) { // More than 1 page.

$pages = ceil ($records/$display);

 } else {

$pages = 1;

}

} // End of p IF.

// Determine where in the database to start returning results...

if (isset($_GET['s']) && is_numeric ($_GET['s'])) {

	$start = $_GET['s'];

} else {

	$start = 0;

}

// Make the query:


	$q = "SELECT * FROM products WHERE category = $product LIMIT $start, $display ";

$r = @mysqli_query ($dbc, $q);


if ($r) { 

	echo '<div align="center"><table cellspacing="3" cellpadding="5" 
width="100%"   style="border:solid; border-width:1px; " bgcolor="#CCCCCC"><tr align="center"><td><b>Product</b></td><td> <b>Description</b> </td><td><b>Phone No</b></td><td><b>Price</b></td></tr>
		';
		
		$bg = '#eeeeee'; // Set the initial background color.

		
		while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		
		$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
		$imgurl = 'uploads/'.$row["image"].'';
		
				
		echo '<tr bgcolor="' . $bg . '" align="center"><td><b>'.$row['prodname'].'</b><br>';
		
		echo '<a href="display.php?id='.$row['id'].'&prod='.$row['prodname'].'"><img src= '.$imgurl.' width=100 height=80 border=0><br> <font size="-2">Click for more details...</font></a></td>' ;
		
		 echo '<td width="150" align="left" >' . $row['proddescr'] . '</td><td align="left">Call Vendor on:<br>'. $row['phone'] . '</td><td align="left">' . $row['price'] . '</td></tr>';
		
		
	}
	
	echo '</table></div>';
mysqli_free_result ($r); 
 mysqli_close($dbc);

	}

if ($pages > 1) {

// Add some spacing and start a paragraph:
 echo '<br /><p>';
	// Determine what page the script is on:
	
		$current_page = ($start/$display) + 1;
		
		// If it's not the first page, make a Previous button:
		
if ($current_page != 1) {
	
echo '<a href="m_category.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
}

// Make all the numbered pages:
	for ($i = 1; $i <= $pages; $i++) {
	
	if ($i != $current_page) {
		echo '<a href="m_category.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
		
	} else {
	
	echo $i . ' ';
	}
	
} // End of FOR loop.


// If it's not the last page, make a Next button:

if ($current_page != $pages) {
	
echo '<a href="m_category.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';

}
echo '</p>'; // Close the paragraph.

} // End of links section.
 
 
}


Thanks for your support and God bless you all

Re: Retrieving Database contents

Posted: Sat Apr 28, 2012 9:48 pm
by califdon
The first thing you must tell us is WHAT isn't working. Do you receive any output? Are there any error messages?

Then confirm that the second code listing is from m_category.php file.

Have you done any debugging?

Re: Retrieving Database contents

Posted: Mon Apr 30, 2012 9:20 am
by abbey4biz
Thanks. I have been able to rectify that.

Re: Retrieving Database contents

Posted: Thu Jun 14, 2012 2:23 am
by jacklinmor
You put following revised code :-
<li>
<a href="<?php echo "m_category.php?product='electrical'"; ?>">Electrical Equipment</a>
</li>

<li class="Furniture">
<a href="<?php echo "m_category.php?product='fashion'"; ?>">Fashion Accessories</a>
</li>

<li>
<a href="<?php echo "m_category.php?product='food'"; ?>">Food & Beverage</a>
</li>

<li class="Furniture">
<a href="<?php echo "m_category.php?product='<span class="posthilit">furniture</span>'"; ?>"><span class="posthilit">Furniture</span></a>
</li>