Forum Moderators: coopster

Message Too Old, No Replies

Need help with script

         

judgenules

5:29 pm on Oct 26, 2007 (gmt 0)

10+ Year Member



Hello there,

I have been having a problem with my script. Been working on it for days now that i dont even know what seems to be the problem. I'm trying to retrieve the data based on its category ID where when the data is retrieved, it categorizes the data on 4 different HTML tables. It works on the first table but wont work on the other three tables. Below is the script:

<?php

include('producthistory.php');
$result = get_producthistory();

?>

<div align="bottom" class="txt">Category : Facial Cream </div>
<table width="581" border="1">
<tr>
<td width="124", height="81"><div align="center" class="txt"><strong>Inventory Category ID</strong></div></td>
<td width="161"><div align="center" class="txt"><strong>Brand ID</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Quantity on Hand </strong></div></td>
<td width="145"><div align="center" class="txt"><strong>Price</strong></div></td>
<td width="124" height="81"><div align="center" class="txt"><strong>Product Name </strong></div></td>
<td width="161"><div align="center" class="txt"><strong>ReStock</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Day</strong></div></td>
</tr>

<?php
//get everything in the fields from top of table to bottom of table

$count = mysql_num_rows($result);

for($i=0; $i<$count; $i++)
{

$row = mysql_fetch_array($result);
$_GET['invCatID'] = $row['invCatID'];


if($_GET['invCatID'] == 1)
{

echo '<tr>';
echo '<td width="124">'.$row['invCatID'].'</td>';

echo '<td width="160">'.$row['brandID'].'</td>';

echo '<td width="100">'.$row['qty'].'</td>';
echo '<td width="100">'.$row['price'].'</td>';
echo '<td width="100">'.$row['productName'].'</td>';
echo '<td width="100">'.$row['reStock'].'</td>';
echo '<td width="100">'.$row['Date'].'</td>';
echo '</tr>';

}
}

?>

</table>

</br></br>

<div align="bottom" class="txt">Category : Hand Lotion </div>
<table width="581" border="1">
<tr>
<td width="124", height="81"><div align="center" class="txt"><strong>Inventory Category ID</strong></div></td>
<td width="161"><div align="center" class="txt"><strong>Brand ID</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Quantity on Hand </strong></div></td>
<td width="145"><div align="center" class="txt"><strong>Price</strong></div></td>
<td width="124" height="81"><div align="center" class="txt"><strong>Product Name </strong></div></td>
<td width="161"><div align="center" class="txt"><strong>ReStock</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Day</strong></div></td> </tr>

<?php

//get everything in the fields from top of table to bottom of
//table

$count = mysql_num_rows($result);

for($i=0; $i<$count; $i++)
{

$row = mysql_fetch_array($result);

$_GET['invCatID'] = $row['invCatID'];

if($_GET['invCatID'] == 2)
{
echo '<tr>';
echo '<td width="250">'.$row['invCatID'].'</td>';

echo '<td width="230">'.$row['brandID'].'</td>';

echo '<td width="100">'.$row['qty'].'</td>';
echo '<td width="100">'.$row['price'].'</td>';
echo '<td width="100">'.$row['productName'].'</td>';
echo '<td width="100">'.$row['reStock'].'</td>';
echo '<td width="100">'.$row['Date'].'</td>';
echo '</tr>';
}

}
?>
</table>
</br></br>
<div align="top" class="txt">Category : Wax</div>
<table width="581" border="1">
<tr>
<td width="124", height="81"><div align="center" class="txt"><strong>Inventory Category ID</strong></div></td>
<td width="161"><div align="center" class="txt"><strong>Brand ID</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Quantity on Hand </strong></div></td>
<td width="145"><div align="center" class="txt"><strong>Price</strong></div></td>
<td width="124" height="81"><div align="center" class="txt"><strong>Product Name </strong></div></td>
<td width="161"><div align="center" class="txt"><strong>ReStock</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Day</strong></div></td> </tr>

<?php
//get everything in the fields from top of table to bottom of
//table

$count = mysql_num_rows($result);

for($i=0; $i<$count3; $i++)
{

$row = mysql_fetch_array($result);

$_GET['invCatID'] = $row['invCatID'];

if($_GET['invCatID'] == 3)
{
echo '<tr>';
echo '<td width="250">'.$row['invCatID'].'</td>';

echo '<td width="230">'.$row['brandID'].'</td>';

echo '<td width="100">'.$row['qty'].'</td>';
echo '<td width="100">'.$row['price'].'</td>';
echo '<td width="100">'.$row['productName'].'</td>';
echo '<td width="100">'.$row['reStock'].'</td>';
echo '<td width="100">'.$row['Date'].'</td>';
echo '</tr>';
}
}

?>
</table>
</br> </br>

<div align="top" class="txt">Category : Other</div>
<table width="581" border="1">
<tr>
<td width="124", height="81"><div align="center" class="txt"><strong>Inventory Category ID</strong></div></td>
<td width="161"><div align="center" class="txt"><strong>Brand ID</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Quantity on Hand </strong></div></td>
<td width="145"><div align="center" class="txt"><strong>Price</strong></div></td>
<td width="124" height="81"><div align="center" class="txt"><strong>Product Name </strong></div></td>
<td width="161"><div align="center" class="txt"><strong>ReStock</strong></div></td>
<td width="124"><div align="center" class="txt"><strong>Day</strong></div></td> </tr>

<?php
//get everything in the fields from top of table to bottom of
//table

$count = mysql_num_rows($result);

for($i=0; $i<$count; $i++)
{

$row = mysql_fetch_array($result);

$_GET['invCatID'] = $row['invCatID'];

if($_GET['invCatID'] >= 4)
{
echo '<tr>';
echo '<td width="250">'.$row['invCatID'].'</td>';

echo '<td width="230">'.$row['brandID'].'</td>';

echo '<td width="100">'.$row['qty'].'</td>';
echo '<td width="100">'.$row['price'].'</td>';
echo '<td width="100">'.$row['productName'].'</td>';
echo '<td width="100">'.$row['reStock'].'</td>';
echo '<td width="100">'.$row['Date'].'</td>';
echo '</tr>';
}

}

?>

I really hope you could help me on this.
Cheers! =)

d40sithui

9:31 pm on Oct 26, 2007 (gmt 0)

10+ Year Member



hmm for a second i think it would be the internal pointer thats culprit since you move through the whole result set displaying each table, which means that by the time you get to table 2, you'll already be at the end of your row data, which means theres no data for table 2(3 and 4) to work with. the seems like a posibility since you're saying it doesnt work for the last 3, but only for the first.
you can try this at the end of every table, do

mysql_data_seek($result, 0);

this will move the pointer back to the beginning.

also, why do you asssign $_GET to another variable?
wouldn't it be simpler if you just do

if($row['invCatID'] == 1){
}

judgenules

4:48 am on Oct 27, 2007 (gmt 0)

10+ Year Member



Thanks d40sithui! You solved my problem. It's all working now! Thanks again..=)))