Click to See Complete Forum and Search --> : PostgreSQL Loops within Loops


gavin_the_dog
01-10-2005, 06:37 PM
Hello all,

I have some PHP code which is supposed to search a table on a database and populate a webpage with the results... heres the catch, there are two results from the first table (max_size, min_size) which i then have to use search for all the sizes between in another table. this has to be done for each result. My guess was to create a Loop which which finds all the results in the first table but then create a loop within this which will find all the results for the secondary search... here is the code, the problem is that it will currently only produce the first result from the first table, can anyone give me any pointers on how to fix this?

<?php
$sql="SELECT * FROM Shoes WHERE name LIKE '$searchinfo%';";

$result_set = pg_Exec($conn, $sql);
$rows = pg_NumRows($result_set);

if ((!$result_set) || ($rows < 1)) {
echo "<h1>Sorry, we do not currently stock this item, please search again.</h1>";
exit;
}

for ($j=0; $j < $rows; $j++) //Create a loop
{
$code = pg_result($result_set, $j, "code");
$name = pg_result($result_set, $j, "name");
$sex = pg_result($result_set, $j, "sex");
$min_size = pg_result($result_set, $j, "min_size");
$max_size = pg_result($result_set, $j, "max_size");
$price = pg_result($result_set, $j, "price");
$image_url = pg_result($result_set, $j, "image_url");

?>
<tr>
<td align="center" class="feat">
<img src="<?php echo $image_url ?>" alt="No Image Available" width="200" height="200">
</td>
<td class="feat">
<p>Product Code: <?php echo $code ?></p>
<p>Product Name: <?php echo $name ?></p>
<p>Product Sex: <?php echo $sex ?></p>
<p>Product Price: £ <?php echo $price ?></p>
<?php
$sql="SELECT euro FROM Sizes WHERE euro BETWEEN '$min_size' AND '$max_size';";

$result_set = pg_Exec($conn, $sql);
$rows = pg_NumRows($result_set);

?>

<p class="link"><select name="sizes">
<option value="" selected>Sizes</option>

<?

for ($j=0; $j < $rows; $j++) //Create a loop
{
$euro = pg_result($result_set, $j, "euro");
?>
<option value="<?php echo $euro ?>"><?php echo $euro ?></option>
<?php
} // end of select loop
?>


</select><br>
<a href="conversion.php">Conversion Guide</a>
</p>


<form action="xxx.php" method="GET">
<p><?php $orderItem=$code; ?></p>
<input type="HIDDEN" value="orderItem" name="orderItem">
<input type="SUBMIT" value="Add to Cart" name="Add to Cart">
</form>
</td>
</tr>
<?
}; //close main loop
?>

any help anyone can give would be really appreciated

gavin_the_dog
01-11-2005, 05:08 AM
If anyone has any thoughts at all, i think its just a simple error with how ive coded it but i cant see it!