Johnny
asked on
multi records from a product database
How do i pull multi records in a problem like this
i have a field of Products_Ordered in a table of Cart_Info with the data of 2,5 {thats the product numbers separated by commas}
related to a table with the ID field in a table called products
i want to pull the Manufacturer, Table and Price fields info for the products table
but heres the catch if the Products_Ordered ha a string like 2,2,5,5 then two of each item was ordered i need the layout to be like this as the output
Items Ordered
2 x Product - 2: Roketa, ATV-21 $1914.95
2 x Product - 5: Roketa, ATV-31 $1714.95
so need the 2,2 and the 5,5 to show the quantity
-------------------------- ---------- -----
include(".\include\mysql_c onnection. php");
$query = "SELECT `Manufacturer`, `Type` FROM `products` WHERE `ID`='".$ID."'";
$result = mysql_query($query, $mysql_link);
while ($row = mysql_fetch_row($result)) {
?? stuck here ???
echo $Totaled_Products . 'x Product - ' . $Manufacturer . ', ' . $Type$ . ' ' . $Price.'<BR />';
?? Stuck Here ??
}
------------------
i don't know how to get totaled_products amount, nor anything else more then what i have given in code im stumped
Thank you in advance for any help and code you may provide
i have a field of Products_Ordered in a table of Cart_Info with the data of 2,5 {thats the product numbers separated by commas}
related to a table with the ID field in a table called products
i want to pull the Manufacturer, Table and Price fields info for the products table
but heres the catch if the Products_Ordered ha a string like 2,2,5,5 then two of each item was ordered i need the layout to be like this as the output
Items Ordered
2 x Product - 2: Roketa, ATV-21 $1914.95
2 x Product - 5: Roketa, ATV-31 $1714.95
so need the 2,2 and the 5,5 to show the quantity
--------------------------
include(".\include\mysql_c
$query = "SELECT `Manufacturer`, `Type` FROM `products` WHERE `ID`='".$ID."'";
$result = mysql_query($query, $mysql_link);
while ($row = mysql_fetch_row($result)) {
?? stuck here ???
echo $Totaled_Products . 'x Product - ' . $Manufacturer . ', ' . $Type$ . ' ' . $Price.'<BR />';
?? Stuck Here ??
}
------------------
i don't know how to get totaled_products amount, nor anything else more then what i have given in code im stumped
Thank you in advance for any help and code you may provide
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
some thing like this maybe but whats the correct php script to do all this
split (Products_Ordered,',')// split on comma
for each split.match { // match the splits ie 2 counted matches of product 2 and 2 counted matches of product 5
$Totaled_Products = split.match.count;//count of $Products_Ordered {would be 2 on both passes}
Products_Match = split.match.single.number; // would be 2 on first pass and second pass would be 5
$query2 = "SELECT * FROM `products` WHERE `ID`='".$Products_Match."' ";// looks up in table id 2 on first pass and second pass id 5
$result2 = mysql_query($query2);
// print our nice table
while ($row2 = mysql_fetch_row($result2)) {
echo "<td valign='top'>".$Totaled_Pr oducts . "x </td><td nowrap> Product - " . $row2[3] . ", " . $row2[5] . "</td><td align='right' valign='top'> $" . $row2[13]."</td>";
}
}// end split match
split (Products_Ordered,',')// split on comma
for each split.match { // match the splits ie 2 counted matches of product 2 and 2 counted matches of product 5
$Totaled_Products = split.match.count;//count of $Products_Ordered {would be 2 on both passes}
Products_Match = split.match.single.number;
$query2 = "SELECT * FROM `products` WHERE `ID`='".$Products_Match."'
$result2 = mysql_query($query2);
// print our nice table
while ($row2 = mysql_fetch_row($result2))
echo "<td valign='top'>".$Totaled_Pr
}
}// end split match
ASKER
ok this works
<?
// start
$Totaled_Products = '2';//count of $Products_Ordered
$query2 = "SELECT * FROM `products` WHERE `ID` IN (".$Products_Ordered.")";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_row($result2)) {
echo "<tr><td valign='top'>".$Totaled_Pr oducts . "x </td><td nowrap> Product - " . $row2[3] . ", " . $row2[5] . "</td><td align='right' valign='top'> $" . $row2[13]."</td></tr>";
}
//end
?>
displays as
------------------------
Items Ordered
2x Product - Roketa, ATV-02 $1345.00
2x Product - Roketa, DB-27 $1245.00
------------------------
but how do i count the $Totaled_Products = '2';//count of $Products_Ordered
great mysql knows not to display multiples but i want to count the multiples and display them
<?
// start
$Totaled_Products = '2';//count of $Products_Ordered
$query2 = "SELECT * FROM `products` WHERE `ID` IN (".$Products_Ordered.")";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_row($result2))
echo "<tr><td valign='top'>".$Totaled_Pr
}
//end
?>
displays as
------------------------
Items Ordered
2x Product - Roketa, ATV-02 $1345.00
2x Product - Roketa, DB-27 $1245.00
------------------------
but how do i count the $Totaled_Products = '2';//count of $Products_Ordered
great mysql knows not to display multiples but i want to count the multiples and display them
ASKER
i did it
Items Ordered
products: 2,2,5,5,7,9,9,9
2x Product - Roketa, DB-27 $1245.00
2x Product - Roketa, ATV-02 $1345.00
1x Product - Roketa, ATV-03 $1245.00
3x Product - Roketa, ATV-04 $1245.00
-------------------------- ---------- ---------- ---------- ---------
<?
// start
echo "products: ".$Products_Ordered."<BR>" ;
//$Totaled_Products = '2';//count of $Products_Ordered
$query2 = "SELECT * FROM `products` WHERE `ID` IN (".$Products_Ordered.")";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_row($result2)) {
if (DEBUG) {
// mysql_info ();
// print out all the rows
echo "<font color='red'><b><BR>------- ---------- ------<BR> ROW_VARS</ b></font>" ;
echo "<pre>";
print_r($row2);
echo "</pre>";
}
$thing = $Products_Ordered;
$search = $row2[0];
$Totaled_Products = substr_count($thing, $search);
echo "<tr><td valign='top'>".$Totaled_Pr oducts . "x </td><td nowrap> Product - " . $row2[3] . ", " . $row2[5] . "</td><td align='right' valign='top'> $" . $row2[13]."</td></tr>";
}
//end
?>
im going to give a grade of B as the question was not fully answered but the in command for mysql got me on the right track
Items Ordered
products: 2,2,5,5,7,9,9,9
2x Product - Roketa, DB-27 $1245.00
2x Product - Roketa, ATV-02 $1345.00
1x Product - Roketa, ATV-03 $1245.00
3x Product - Roketa, ATV-04 $1245.00
--------------------------
<?
// start
echo "products: ".$Products_Ordered."<BR>"
//$Totaled_Products = '2';//count of $Products_Ordered
$query2 = "SELECT * FROM `products` WHERE `ID` IN (".$Products_Ordered.")";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_row($result2))
if (DEBUG) {
// mysql_info ();
// print out all the rows
echo "<font color='red'><b><BR>-------
echo "<pre>";
print_r($row2);
echo "</pre>";
}
$thing = $Products_Ordered;
$search = $row2[0];
$Totaled_Products = substr_count($thing, $search);
echo "<tr><td valign='top'>".$Totaled_Pr
}
//end
?>
im going to give a grade of B as the question was not fully answered but the in command for mysql got me on the right track
ASKER
display something like
Items Ordered
2 x Product - 2: Roketa, ATV-21 $1914.95
2 x Product - 5: Roketa, ATV-31 $1714.95
i have the field Products_Ordered in a table of Cart_Info has the info of 2,2,5,5 so that be product ID two times for ID 2 and two times for product id 5
there are two tables one Cart_info and the second products
now i know id have to loop all this as it reads the field Products_Ordered in a table of Cart_Info but i dont get how to do this.
if i was doing this as a person id match up the duplicates and then lookup the record info for each product id
then print my results
the cart_info table just has how many items where ordered for a customer in the format of 2,2,5,5 they got 2 of product id 2 and 2 of product id 5. i want to be able to display this by above layout
does this make more sense?