Re: Multiple MySQL Queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 28, 2009 at 10:11 AM, <sono-io@xxxxxxxxxxxxx> wrote:
>        This may be more of a MySQL question than PHP, but I'm hoping someone
> can point me in the right direction.  I have working code (below) that pulls
> data from a particular category in our db.  I'd like to be able to pull data
> from multiple categories in the same db and place them on the same page.
>
>        I've been working on this for the last 4 days with no luck.  Some
> pages say that you can't do multiple MySQL queries while others say there is
> a workaround but I haven't found it.  Does anyone know how to do this?
>
> Thanks,
> Frank
>
> --------
>
> <?php require_once("/home/balcone/db_login.php"); ?> // in header
>
> <?php
>        $item_list = "";
>        $cat1 = "01100-01200-01300-06403";
>        $result = mysql_query("SELECT itemid,description,unitprice FROM
> catalog WHERE categories='" . $cat1 . "'  ORDER BY itemid",$db);
>
> while ($item = mysql_fetch_assoc($result))
> {
> $item_list .= "<tr><td>" . $item['itemid'] . "</td>
>        <td><a href=\".../shop.cgi?c=detail.htm&amp;itemid=" .
> $item['itemid'] . "=1\">". $item['description'] ."</a></td>
>        <td align=\"right\">$". money_format('%i', $item['unitprice'])
> ."</td>
>        <td></tr>";
> }
> echo "<table border=\"1\"><tr><th>Item ID</th><th>Description<br /><font
> size=\"-1\">(Click for more info)</font></th><th>Price
> Each</th><th>Purchase</th></tr>$item_list</table>";
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

change it to an IN clause for the categories

$result = mysql_query("SELECT itemid,description,unitprice FROM
catalog WHERE categories in('$cat1',"$cat2',$cat3','$catN')  ORDER BY
itemid",$db);


-- 

Bastien

Cat, the other other white meat

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux