# php & sql challange from beginner

**URL:** <https://www.phphelp.com/t/php-sql-challange-from-beginner/20437>\
**Category:** General PHP Help\
**Created:** [June 10, 2013, 5:54pm UTC](https://www.phphelp.com/t/php-sql-challange-from-beginner/20437 "2013-06-10T17:54:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://www.phphelp.com/uploads/default/original/2X/2/243e9ed5d93c5653ce3186f18df16e019ce38445.png) [@system](https://www.phphelp.com/u/system)\
**Post date:** [June 10, 2013, 5:54pm UTC](https://www.phphelp.com/t/php-sql-challange-from-beginner/20437/1 "2013-06-10T17:54:29Z")

</div>

Hello

Not sure if my issue should be posted here or if I should find an SQL forum. (I am brand new to SQL)

Here is the scope outlined of my project:  
SQL Query objective

3 Tables:  
Table #1 – product

product\_ID , product\_name , page\_group , default\_price  
TILE1212 , 12 X 12 Tile , ElsoT , 40.35  
TILE810 , 8 X 10 Tile , ElsoT , 29.75  
TILE88 , 8 X 8 Tile , ElsoT , 27.95  
TILE68 , 6 X 8 Tile , ElsoT , 25.75

Table #2 – product\_options

option\_number , product\_ID  
1920 , TILE1212  
1945 , TILE810  
1947 , TILE88  
1966 , TILE68

Table #3 – option\_choices

option\_number , disp\_value , percentage  
1920 , 1-2 , 0.000  
1920 , 3-11 , 0.063  
1920 , 12-23 , 0.094  
1920 , 24-35 , 0.125  
1920 , 36-47 , 0.156  
1920 , 48-59 , 0.188  
1920 , 60-71 , 0.219  
1920 , 72+ , 0.250  
1945 , 1-2 , 0.000  
1945 , 3-11 , 0.000  
1945 , 12-23 , 0.000  
1945 , 24-35 , 0.000  
1945 , 36-47 , 0.000  
1945 , 48-59 , 0.000  
1945 , 60-71 , 0.000  
1945 , 72+ , 0.000  
1947 , 1-2 , 0.000  
1947 , 3-11 , 0.000  
1947 , 12-23 , 0.000  
1947 , 24-35 , 0.000  
1947 , 36-47 , 0.000  
1947 , 48-59 , 0.000  
1947 , 60-71 , 0.000  
1947 , 72+ , 0.000  
1966 , 1-2 , 0.000  
1966 , 3-11 , 0.000  
1966 , 12-23 , 0.000  
1966 , 24-35 , 0.000  
1966 , 36-47 , 0.000  
1966 , 48-59 , 0.000  
1966 , 60-71 , 0.000  
1966 , 72+ , 0.000

Objective is to create a pricing grid with column headings:  
Tile size, to be populated with “product.product\_name”  
next 8 column headings to be populated with “option\_choices.disp\_value”  
These 8 columns under “option\_choices.disp\_value” to be polulated with “option\_choices.percentage”

This has gotten me close but not yet what I am looking for;

[code]$group\_query="SELECT \* FROM product, product\_options, option\_choices  
WHERE  
product.page\_group=‘ElsoT’ AND  
product.product\_ID=product\_options.product\_ID AND  
product\_options.option\_number=option\_choices.option\_number  
";

$group\_result=mysql\_query($group\_query);

$num=mysql\_numrows($group\_result);[/code]

the $num here results in all 32 records but really only want the 4 product records.

Next we build our display table Heading using while loop to populate column headings:

[code]

\<?php $numss=8; $iii=0; while ($iii \< $numss) { $f9=mysql\_result($group\_result,$iii,"disp\_value"); ?\> \<?php $iii++; } ?\> [/code]

Last the actual display table

[php]\<?php  
$i=0;  
do  
{

$f3=mysql\_result($group\_result,$i,“product\_name”);  
$f4=mysql\_result($group\_result,$i,“default\_price”);  
?\>

\<?php $nums=8; $ii=0; while ($ii \< $nums) { $f8=mysql\_result($group\_result,$ii,"percentage");

?\>

\<?php $ii++; } ?\> \<?php $i++; } while ($i \< $num) ; ?\>

| Size | \<?php echo $f9; ?\> |
| \<?php echo $f3; ?\> | \<?php echo $f4; ?\> | \<?php echo $f8; ?\> |

[/php]

obstical:  
What I am after is for this example to display:  
4 rows plus the header row with once only tile name first column  
Base price in second column  
percentage discounts to loop to remain in the same row as the tile it represents.

Hello

Not sure if my issue should be posted here or if I should find an SQL forum. (I am brand new to SQL)

Here is the scope outlined of my project:  
SQL Query objective

3 Tables:  
Table #1 – product

product\_ID , product\_name , page\_group , default\_price  
TILE1212 , 12 X 12 Tile , ElsoT , 40.35  
TILE810 , 8 X 10 Tile , ElsoT , 29.75  
TILE88 , 8 X 8 Tile , ElsoT , 27.95  
TILE68 , 6 X 8 Tile , ElsoT , 25.75

Table #2 – product\_options

option\_number , product\_ID  
1920 , TILE1212  
1945 , TILE810  
1947 , TILE88  
1966 , TILE68

Table #3 – option\_choices

option\_number , disp\_value , percentage  
1920 , 1-2 , 0.000  
1920 , 3-11 , 0.063  
1920 , 12-23 , 0.094  
1920 , 24-35 , 0.125  
1920 , 36-47 , 0.156  
1920 , 48-59 , 0.188  
1920 , 60-71 , 0.219  
1920 , 72+ , 0.250  
1945 , 1-2 , 0.000  
1945 , 3-11 , 0.000  
1945 , 12-23 , 0.000  
1945 , 24-35 , 0.000  
1945 , 36-47 , 0.000  
1945 , 48-59 , 0.000  
1945 , 60-71 , 0.000  
1945 , 72+ , 0.000  
1947 , 1-2 , 0.000  
1947 , 3-11 , 0.000  
1947 , 12-23 , 0.000  
1947 , 24-35 , 0.000  
1947 , 36-47 , 0.000  
1947 , 48-59 , 0.000  
1947 , 60-71 , 0.000  
1947 , 72+ , 0.000  
1966 , 1-2 , 0.000  
1966 , 3-11 , 0.000  
1966 , 12-23 , 0.000  
1966 , 24-35 , 0.000  
1966 , 36-47 , 0.000  
1966 , 48-59 , 0.000  
1966 , 60-71 , 0.000  
1966 , 72+ , 0.000

Objective is to create a pricing grid with column headings:  
Tile size, to be populated with “product.product\_name”  
next 8 column headings to be populated with “option\_choices.disp\_value”  
These 8 columns under “option\_choices.disp\_value” to be polulated with “option\_choices.percentage”

This has gotten me close but not yet what I am looking for;

[code]$group\_query="SELECT \* FROM product, product\_options, option\_choices  
WHERE  
product.page\_group=‘ElsoT’ AND  
product.product\_ID=product\_options.product\_ID AND  
product\_options.option\_number=option\_choices.option\_number  
";

$group\_result=mysql\_query($group\_query);

$num=mysql\_numrows($group\_result);[/code]

the $num here results in all 32 records but really only want the 4 product records.

Next we build our display table Heading using while loop to populate column headings:

[code]

\<?php $numss=8; $iii=0; while ($iii \< $numss) { $f9=mysql\_result($group\_result,$iii,"disp\_value"); ?\> \<?php $iii++; } ?\> [/code]

Last the actual display table

[php]\<?php  
$i=0;  
do  
{

$f3=mysql\_result($group\_result,$i,“product\_name”);  
$f4=mysql\_result($group\_result,$i,“default\_price”);  
?\>

\<?php $nums=8; $ii=0; while ($ii \< $nums) { $f8=mysql\_result($group\_result,$ii,"percentage");

?\>

\<?php $ii++; } ?\> \<?php $i++; } while ($i \< $num) ; ?\>

| Size | \<?php echo $f9; ?\> |
| \<?php echo $f3; ?\> | \<?php echo $f4; ?\> | \<?php echo $f8; ?\> |

[/php]

obstical:  
What I am after is for this example to display:  
4 rows plus the header row with once only tile name first column  
Base price in second column  
percentage discounts to loop to remain in the same row as the tile it represents.

To see the real results to see the objective please see my working page at: [http://www.elsographics.com/tiles/elso.php](http://www.elsographics.com/tiles/elso.php)

Thank you in advance for anyone willing to help me untangle this so I can get the results/display I am after. I am very new with SQL.

Thank you in advance for anyone willing to help me untangle this so I can get the results/display I am after. I am very new with SQL.
