|
Posted by IndyTim on 12/22/05 02:34
MattMika wrote:
> Got it, thnx anyway...
>
> <tr><td>
> <table><tr>
> <?
> $query = mysql_query("SELECT * FROM orders_status
> LEFT JOIN orders ON orders.order_status=orders_status.status_id
> ");
> while ($r = mysql_fetch_array($query))
> {
> $status_name = $r["status"];
> $status_id = $r["status_id"];
> $num = count($r["order_id"]);
> echo "<td class=\"box\"><a class=\"alert\"
> href=\"orders.php?status=$status_id&statusname=$status_name\">$status_name
> - $num</a></td>";
> }
> ?>
> </tr></table>
> </td></tr>
>
>
>
> MattMika wrote:
>
>
>>On my orders page I have this code to generate a simple menu of orders
>>statuses so users can browse orders by status.
>>
>><tr><td>
>><table><tr>
>><?
>>$query = mysql_query("SELECT * FROM orders_status");
>>while ($r = mysql_fetch_array($query))
>>{
>>$status_name = $r["status"];
>>$status_id = $r["status_id"];
>>echo "<td class=\"box\"><a class=\"alert\"
>>href=\"orders.php?status=$status_id&statusname=$status_name\">$status_name
>>- $num</a></td>";
>>}
>>?>
>></tr></table>
>></td></tr>
>>
>>What I want to do is join my orders table so that I can echo the
>>number($num) of orders matching each status.
>>
>>Something like;
>>Pending-4, Processing-3, Confirmed-2, Cancelled-1
>>
>>I'll have to join the orders table, but Im not sure how to go about
>>getting the count.
>>
>>My tables look like this:
>>
>>TABLE_ORDERS
>>------------
>>order_id order_status user_id
>>1 2 1
>>
>>TABLE_ORDERS_STATUS
>>-------------------
>>status_id status
>>1 Pending
>>2 Processing
>>3 Confirmed
>>4 Cancelled
>>
>>TIA for any suggestions or pointers.
>>
>
>
Matt,
Another approach if all you are interested in is the number of records
returned from the query is to use the function mysql_num_rows($query).
With this function, you wouldn't have to dive into the actual extraction
of data via the mysql_fetch_array(...).
FWIW,
IndyTim
Navigation:
[Reply to this message]
|