Skip to main content
Inspiring
Sep 19, 2012 6:31 PM UTC
Answered

filtering multiple recordset.

I have posted 2 more discussions on the forum so i do aplogise but i am unsure the best way to describe what i am looking for

i have a product page. with links to individual products

<a href="product-description.php?ID=<?php echo $row_Recordset1['ID']; ?>"><img src="../images/AW/thumbs/<?php echo $row_Recordset1['imageSmall']; ?>"/></a>

on the product page i need to call in other tables based on the catagory of the product and sizes of the product,

i have created multiple recordsets joining the table but need help with the filtering of the information

i have a recordset showing the product information (basics - name, size, price)

$colname_Recordset1 = "-1";

if (isset($_GET['ID'])) {

  $colname_Recordset1 = $_GET['ID'];

}

mysql_select_db($database_beau, $beau);

$query_Recordset1 = sprintf("SELECT * FROM beauProd WHERE ID = %s", GetSQLValueString($colname_Recordset1, "int"));

$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

i have a recordset to join the size table with the product table

$colname_Recordset2 = "-1";

if (isset($_GET['SizeProdID'])) {

  $colname_Recordset2 = $_GET['SizeProdID'];

}

mysql_select_db($database_beau, $beau);

$query_Recordset2 = sprintf("SELECT * FROM beauProd, beauSizes WHERE beauSizes.SizeProdID = beauProd.SizeProdID AND beauProd.SizeProdID = %s", GetSQLValueString($colname_Recordset2, "int"));

$Recordset2 = mysql_query($query_Recordset2, $beau) or die(mysql_error());

$row_Recordset2 = mysql_fetch_assoc($Recordset2);

$totalRows_Recordset2 = mysql_num_rows($Recordset2);

in the body i have a select list that needs to display the records of all the products in that catagory

<form id="FormName" action="" method="get" name="FormName">

            <table width="300">

              <tr>

                <td><select name="name" class="text" id="selectName">

                  <option value="Select Design">Select Design</option>

                  <?php

do {

?>

                  <option value="<?php echo $row_Recordset1['ID']; ?>"><?php echo $row_Recordset1['name']; ?></option>

                  <?php

} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

  $rows = mysql_num_rows($Recordset1);

  if($rows > 0) {

      mysql_data_seek($Recordset1, 0);

            $row_Recordset1 = mysql_fetch_assoc($Recordset1);

  }

?>

                </select></td>

                <td><div align="right">

                  <input type="submit" name="button" id="button" value="select" />

                </div></td>

              </tr>

            </table>

          </form>

and a select list that needs to show the sizes of each product

<select name="os0" class="text" id="Cos0">

    <option value="select Category">Select Size</option>

    <?php

do {

?>

    <option value="<?php echo $row_Recordset2['SizeProdID']; ?>"><?php echo $row_Recordset2['from'] . " - " . $row_Recordset2['to'] ; ?></option>

    <?php

} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));

  $rows = mysql_num_rows($Recordset1);

  if($rows > 0) {

      mysql_data_seek($Recordset2, 0);

            $row_Recordset2 = mysql_fetch_assoc($Recordset2);

  }

?>

  </select>

the way i have it at the moment i cant get either select list to work. CAN ANYONE ADIVSE PLEASE

thanks in advance

This topic is closed to new replies. Start a new post to keep the conversation going.
David_Powers
David_PowersCorrect answer
Inspiring
Sep 21, 2012 11:37 AM UTC

Hello David

Thanks for getting back to me.

so each table should just have one linked feild

so the product table is ok linked by catID?

but then i need to remake to sizes? This is what i cant get my head around. Sorry about this.

I need to create a size table with

a size ID and a size name

what do i do if i have sizes that vary

0-3 months

3-6 months

6-12 months

12-24 months

small

meduim

large

2 years

3 years

4 years

can these all go into one field?

could i just make a select list and store them like that?

thanks so much for you time so far, this is the last part of the site i have to do.


Jonathan Fortis wrote:

can these all go into one field?

No. One field should hold one piece of information.

Sizes table

size_id
size
10-3 months
23-6 months
36-12 months
412-24 months
5small
6medium
7large
82 years
93 years
104 years

Categories table

cat_id
category
1baby
2toddler
3child

Products table

prod_id
cat_id
product
11Baby-gro
21Bib
32T-shirt

Stock table

prod_id
size_id
stock
1150
120
3335
3420
3823
390
31015

In the stock table, prod_id and size_id must be declared as a joint primary key. This ensures that only one record can be created for each combination of product and size.

There are 50 Baby-gros for 0-3 months in stock. Baby-gros for 3-6 months are normally available, but currently out of stock.

T-shirts for 6-12 months, 12-24 months, and ages 2-4 are normally available. There is stock for all except age 3.

[Edited to correct the prod_id values in the stock table]

17 replies

David_Powers
Inspiring
Sep 19, 2012 7:14 PM UTC

Jonathan, I've been trying to help you sort out your problems, but wasn't available to visit the forums for a couple of days. Posting multiple threads about your difficulties is only going to confuse matters even further.

What do you mean by not being able to get either select list to work? The PHP code looks fine, so it's presumably a problem with your SQL query not returning the values you expect.

I suspect the problem lies in the way you have structured your database. Looking at the tables in one of your other threads, I can't work out how your sizes table relates to the products table. It seems as though you need a cross-reference table which contains two IDs as a joint primary key.

Let's say you have two products: a red T-shirt and a blue one.

ProdID      Product_name

1               Red T-shirt

2               Blue T-shirt

You also have five sizes:

SizeID     Size

1             Small

2             Medium

3             Large

4             Extra large

5             XXL

You can store the sizes like this:

ProdID   SizeID

1            3

1            4

2            1

2            2

2            4

The red T-shirt is available only in large and extra large, but the blue T-shirt is in small, medium, and extra large.

Translate
Inspiring
Sep 19, 2012 7:30 PM UTC

i am very sorry i have posted multiple thread, its i was unsure what i was really asking in the topic.. the reason i have made my sizes the way i have is so that they can manually be changed when they are out of stock. i have given each product its own size, this way there is a list with the product and the size and when said product is sold out i have a check box to say so.

it looks like with the above logic i can do this.

on the product description page i am trying to call in the full list of products from that catagory

using the CatID to join the product and the catagory

and the sizes from the product

using the SizeProdID to join the product and the size table.

then filter what i need out from there. but as you can see that isnt doing what i want it to and the product list is just showing the product that has been selected and the sizes is showing nothing,

Translate