i have a prblem of 5 hours aprox... I can Print an mysql select to a table from one array before i combine... my code is: in Cookies there are this array Array( [] => [1254] => 325 [2112] => 77 [354] => 2 ) where [1254 is cod of product] => 325 is quant
<table width="100%" border="0" cellpadding="3" cellspacing="2">
<tr><!--prepare row of head cols html static-->
<td> COD</td>
<td> PROD</td>
<td>CAT</td>
<td>**CANT**</td>
</tr>
<?php
////array in cookie to variable php $rr
$rr = $_COOKIE['coo'];
foreach ($rr as &$arr){////for each element of $rr generate one register
$SQL="SELECT cod_pro,name,cod_cat,('$arr') AS quant FROM products
WHERE cod_pro=".$arr."
ORDER BY cod_cat asc";
$result=mysql_query($SQL,$lnk) ;
if (mysql_num_rows($result)>0){ //if exist anyone
while($registers=mysql_fetch_array($result,MYSQL_ASSOC)){
////print each row here all right
echo "<tr><td>".$registers["cod_pro"]."</td>"."<td>".$registers["name"]."/td>"
."<td>".$registers["cod_cat"]."/td><td>".$registers["quant"]."</td></tr>";
////$registers["quant"] i want add one col with this value from cookie
?>
<?php }?>
<?php }
} ?>
</table>
The problem is $registers["cant"] how i can do the SELECT my sql, for give this output; [] => [1254] => 325 [2112] => 77 [354] => 2
COD (pk) NAME COD_CAT **quant** This i can´t show
--------------------------------------------
1254 Car (bd) 1 (bd) **325**
2112 Cicles(bd) 2 (bd) **77**
354 toys (in bd) 3 (bd) **2**
Any idea Thanks
I think I understand what you are asking. I cleaned up your code, and made the fix I think your wanting. There is no reason to try and pass data into that SQL query, just to pull it back out.
Just reference the data directly in the loop.
I dont have any idea what this code actually does, so what I wrote below may not work...
But its the best I can do from what I understand.
<table width="100%" border="0" cellpadding="3" cellspacing="2">
<tr>
<td> COD</td>
<td> PROD</td>
<td>CAT</td>
<td>**CANT**</td>
</tr>
<?php
$rr = $_COOKIE['coo'];
foreach ($rr as $name => &$arr)
{
$SQL = "SELECT cod_pro,name,cod_cat FROM products
WHERE cod_pro=".$arr."
ORDER BY cod_cat asc";
$result=mysql_query($SQL,$lnk) ;
if (mysql_num_rows($result)>0)
{
while($registers=mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr><td>".$registers["cod_pro"]."</td>"."<td>".$registers["name"]."/td>"."<td>".$registers["cod_cat"]."/td><td>".$name."</td></tr>";
}
}
}
?>
</table>
after doing the select, get the results and then do the for each loop with the results
Now you are going the reverse way
Also you are having a single tr against multiple tr in your loop.
First try to make flow chart, then code.
Suggest you to go through data structure books and try to code and solve problems there.