Jump to content

Not all items are being displayed from MySQL DB


tikiman

Recommended Posts

<?php

//Select statement to be sent to MYSQL Database ordered by title
$query = "SELECT * FROM `products` WHERE title = 'title1' ORDER BY item_num";

//Result set from the MYSQL Query
$result = mysql_query($query) or die(mysql_error());

//Counter to keep track of how many displayed
$count = 1;

//Initiate the table to hold the items
echo "<table><tr>";


//While Loop to fetch and display all the products in nested tables
while($newArray = mysql_fetch_array($result, MYSQL_ASSOC))	{

//All the columns of the table in the database
$item_num = $newArray['item_num'];
$units_per_case = $newArray['units_per_case'];
$pieces_per_unit = $newArray['pieces_per_unit'];
$weight = $newArray['weight'];
$section = $newArray['section'];
$title = $newArray['title'];
$desc = $newArray['desc'];
$image_id = $newArray['image_id'];

//If there are less than 3 items in the table it adds the next item to it
if($count <= 3)	{

//Prints out the rows and columns in the table

echo "

	<td>
	<table width='210'>
	<tr>
	<td height='70'> ";
	$filename = "images/products/new/$image_id.png";
	if (file_exists($filename)) {
   			echo "<a class='popup' href='#'><img src='images/products/new/$image_id.png'><span><img src='images/products/big/$image_id.png'></span></a>";
	} else {
   			echo "<img src='images/products/new/holder.png'>";
	} 
echo "	
	</td>
	</tr>
	<tr>
	<td>item # $item_num</td>
	</tr>
	<tr>
	<td>$desc</td>
	</tr>
	</table>
	</td>

";

$count++;

}
 else if($count > 3)	{

	//Closes the table and starts a new one when there are more than 3 items in the current table
	$count = 1;
	echo "</tr>";
	echo "</table>";
	echo "<br>";
	echo "<table>";
	echo "<tr>";

}

}
if($count = 1)	{

	//Closes the empty table that is created when there are only 3 left
	echo "</tr>";
	echo "</table>";
	echo "<br>";

}
?>

 

 

Some of the items are not being displayed, usually 1 per title, any ideas why?

I can't see anywhere in your code that you connected to DB or include any file to do so.

 

Here is:

 

<?php

//DB Config
$user = 'user here';
$pass = 'password here';
$host = 'localhost';
$dbname = 'Data Base name here';

// Connect to DB
$db = mysql_connect ($host, $user, $pass) or die ('Error: ' . mysql_error());
mysql_select_db ($dbname);

//Select statement to be sent to MYSQL Database ordered by title
$query = "SELECT * FROM `products` WHERE title = 'title1' ORDER BY item_num";

//Result set from the MYSQL Query
$result = mysql_query($query) or die(mysql_error());

//Counter to keep track of how many displayed
$count = 1;

//Initiate the table to hold the items
echo "<table><tr>";


//While Loop to fetch and display all the products in nested tables
while($newArray = mysql_fetch_array($result, MYSQL_ASSOC))	{

//All the columns of the table in the database
$item_num = $newArray['item_num'];
$units_per_case = $newArray['units_per_case'];
$pieces_per_unit = $newArray['pieces_per_unit'];
$weight = $newArray['weight'];
$section = $newArray['section'];
$title = $newArray['title'];
$desc = $newArray['desc'];
$image_id = $newArray['image_id'];

//If there are less than 3 items in the table it adds the next item to it
if($count <= 3)	{

//Prints out the rows and columns in the table

echo "

	<td>
	<table width='210'>
	<tr>
	<td height='70'> ";
	$filename = "images/products/new/$image_id.png";
	if (file_exists($filename)) {
   			echo "<a class='popup' href='#'><img src='images/products/new/$image_id.png'><span><img src='images/products/big/$image_id.png'></span></a>";
	} else {
   			echo "<img src='images/products/new/holder.png'>";
	} 
echo "	
	</td>
	</tr>
	<tr>
	<td>item # $item_num</td>
	</tr>
	<tr>
	<td>$desc</td>
	</tr>
	</table>
	</td>

";

$count++;

}
 else if($count > 3)	{

	//Closes the table and starts a new one when there are more than 3 items in the current table
	$count = 1;
	echo "</tr>";
	echo "</table>";
	echo "<br>";
	echo "<table>";
	echo "<tr>";

}

}
if($count = 1)	{

	//Closes the empty table that is created when there are only 3 left
	echo "</tr>";
	echo "</table>";
	echo "<br>";

}
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.