You are here: Re: query count help « PHP SQL « IT news, forums, messages
Re: query count help

Posted by MattMika on 12/21/05 20:42

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.
>

--
MattMika

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация