/    Sign up×
Community /Pin to ProfileBookmark

PostgreSQL Loops within Loops

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@gavin_the_dogauthorJan 11.2005 — If anyone has any thoughts at all, i think its just a simple error with how ive coded it but i cant see it!
×

Success!

Help @gavin_the_dog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...