I have two tables and I am trying to step through them
using mysql arrays.
I think that maybe I have not understood the foreach loop
properly. I have two of them, it looks logical to me but
it is throwing up a strange result :confused:
This is the code I have:
Expand|Select|Wrap|Line Numbers
- sql_prod = "SELECT * FROM products WHERE owner_id = '{$_SESSION['member']}' ";
- $result_prod = mysql_query($sql_prod) or die("could not execute FIND MEMBER query.". mysql_error());
- if(mysql_num_rows($result_prod) == 0 ){
- echo "<td>You have no products recorded!</td><td>0</td><td>0</td><td>0</td>";
- } // end if
- else {
- $row_prod = mysql_fetch_assoc($result_prod);
- echo "<br>Member: {$_SESSION['member']}<br>";
- print_r($row_prod);
- foreach ($row_prod as $value_prod) {
- $sql_req = "SELECT * FROM requests WHERE prod_id = '{$value_prod['prod_id']}' ";
- $result_req = mysql_query($sql_req) or die("could not execute find REQUEST
- query.". mysql_error());
- $num_req = mysql_num_rows($result_req);
- if(mysql_num_rows($result_req) == 0 ){
- echo "<td>{$row_prod['prod_name']}</td><td>0</td><td>0</td><td>0</td>";
- } // end if
- else {
- $row_req = mysql_fetch_assoc($result_req);
- $req_num = 0;
- $rep_num = 0;
- $unres = 0;
- foreach ($row_req as $value_req) {
- $req_num = $req_num+1;
- $rep_num = $rep_num+1;
- if ($value_req['request'] != "" && trim($value_req['reply']) == "") {
- $unres = $unres+1;
- } // end if
- } // end foreach
- echo
- "<td>{$row_prod['prod_name']}</td><td>$req_num</td><td>$rep_num</td><td>$unres</td>";
- } // end else
- echo "</tr><tr>";
- } // end foreach
- echo "</tr></table>";
- } // end else
Member: sai612As you can see it is working a bit !
Array ( [prod_id] => bmm001 [live] => y [type] => L [cat_cd] => [owner_id] => sai612 [prod_name] => 30 Day BM Blitz [request] => 0 )
Notice: Uninitialized string offset: 0 in /home/focus7/public_html/mem_start1.php on line 77
Product Requests Replies Unresolved
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
30 Day BM Blitz 0 0 0
But I don't know why I get that error, or what it means.
Also the result is odd as I only have ONE row in the "requests" table for
that product.
Can anyone see where I have gone wrong ?
Thanks :)