Jump to content

[SOLVED] Looping around to recordsets


mr_jim

Recommended Posts

Hi everyone,

 

Got a problem involving looping around 2 sets of records at the same time and comparing them. Basically I have 2 tables:

size_ref

size_id

size

 

garment_sizes

product_id

size_id

 

At the moment I loop around 'size_ref' to create a number of checkboxes. I want to loop compare the two recordsets to "check" the checkbox if the value in 'garment_sizes' matches the value in 'size_ref' (they are linked on 'size_id'). I have some code below but it is does not currently work, as I have been playing around with it to try and get this to work: -

 

<?php
$querysize = "SELECT * FROM size_ref ORDER BY size_id";
$resultsize = mysql_query($querysize);
f ($resultsize){
} else {
echo "Error connecting to database. Please contact the administrator of the site.";
exit();
}

$querygs = "SELECT DISTINCT size_id FROM garment_sizes WHERE product_id = $pid ORDER BY size_id";
echo $querygs;
$resultgs = mysql_query($querygs);
if ($resultgs){
} else {
echo "Error connecting to database. Please contact the administrator of the site.";
exit();
}

$i =1;
echo "<i>(More than one can be selected)</i><table border=\"0\"><tr>";

while ($size = mysql_fetch_array ($resultsize, MYSQL_ASSOC)) {
$sizeid = $size['size_id'];
$sizename = $size['size'];
$check = "";

//I had another loop that went around garment_sizes and checked here, but deleted it as it didnt work. It simply repeated every record. 

if ($i == 2) {
echo "<td><input type=\"checkbox\" value=\"$sizeid\" name=\"size[]\" $check> $sizename</td></tr>\n";
$i =1;
} else {
echo "<td><input type=\"checkbox\" value=\"$sizeid\" name=\"size[]\" $check> $sizename</td>\n";
$i = $i + 1;
}

//The loop ended here

}
echo "<td> </td></tr></table>";
mysql_free_result($resultsize);
mysql_free_result($resultgs);		  
?>

 

Please disregard the fact I have no connection etc as this is all done further up the page. Help would be much appreciated.

 

Jim

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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