Help with foreach loop over two queries
Posted: Fri Jan 02, 2009 11:25 am
I am fairly new to php and have read so many posts and tutorials, but still cannot seem to find one that addresses the problem I have. I hope someone here can tell me if what I am attempting is possible and, if so, how.
Table 1 - style_img. Contains the style numbers and images.
Table 2 - products. Contains all information about each style, size, style no., sku, etc.
My objective is to create an ordering page for each style. Each style is available in 9 or 10 sizes and 28 - 32 colors. I have been attempting to code for 1 cell of a table, then use a for or foreach to loop through all the colors/sizes to display one color with corresponding sizes in each cell. I then wanted to apply pagination to display 3 cells across the page; 4 or 5 rows on each page.
The linked page is a sample I created by using only one color in my code so I could better explain what I am attempting.
http://www.testsite.uniqueuniforms.com/testWW.php
Here is the php code I have (without the foreach):
When I try to use a foreach loop on this, all the garment images are side-by-side, then the sizes are grouped as all XS, one for each color; all S, one for each color, etc. What I've been searching for is a way to loop through both queries, complete that cell of information, then move on to the next color in the array. Tried GROUP BY, for, foreach, even a function. Right now, I'm just frustrated and can't seem to translate one more "Hello World" tutorial to attempt this again. Please help!! 
Table 1 - style_img. Contains the style numbers and images.
Table 2 - products. Contains all information about each style, size, style no., sku, etc.
My objective is to create an ordering page for each style. Each style is available in 9 or 10 sizes and 28 - 32 colors. I have been attempting to code for 1 cell of a table, then use a for or foreach to loop through all the colors/sizes to display one color with corresponding sizes in each cell. I then wanted to apply pagination to display 3 cells across the page; 4 or 5 rows on each page.
The linked page is a sample I created by using only one color in my code so I could better explain what I am attempting.
http://www.testsite.uniqueuniforms.com/testWW.php
Here is the php code I have (without the foreach):
Code: Select all
include('admin/misc.inc');
$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server" . mysqli_error());
$input = "input type=\"text\" size=\"2\" name=";
$colors = array('Black', 'Celadon', 'Chocolate', 'Ciel');
echo "<table width:750px cellpadding='0' cellspacing='0'>";
echo "<tr>";
$result = mysqli_query($cxn,"SELECT * FROM style_img WHERE style_no='4112'")or die ("problem with query" . mysqli_error());
while($row = mysqli_fetch_assoc($result))
{
echo "<td width='250'>";
echo "<img src='../images/{$row['photo_sm']}' border='0' align='left'>";
echo "</p>";
}
$result2= mysqli_query($cxn,"SELECT * FROM products WHERE style_no='4112' ORDER BY size_rank") or die ("problem with second query" . mysqli_error());
while($row = mysqli_fetch_array($result2))
{
echo "<p><font face='Arial Narrow' size='2'><$input\"{$row['price']}_{$row['sku']} {$row['vendor_name']} {$row['color_name']} {$row['desc']} #{$row['style_no']}-{$row['color_code']}-{$row['size']}(nontaxable)_{$row['shipping']}\"> {$row['size']}@ \${$row['price']} each</p>";
}
echo "</td>";
echo "</tr>";
echo "</table>";