Re: select * from...

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

 



Sounds like you want to do an inner(?) join on the two tables.  This will show you where you have matches between the two tables but also show you the items that don't match (no special instructions).  If I understand right, you have an "order_id" in both "orders" and "special_orders_instructions" right?  You can just link on that without needed to add any special columns.  Try something like this:


SELECT o.order_id, o.otherordercolumn, soi.order_id,j soi.otherinstructioncolumns
FROM orders AS o LEFT JOIN special_orders_instructions AS soi ON o.order_id = soi.order_id


Then in PHP just check to see if soi.order_id is blank or not.  If it is, there's no special orders to be found.  If it's not blank, then check out the SOI variables.


Hope that helped a little.  Forgive any typos... wanted to respond quick so I could go home. :)

-TG

= = = Original message = = =

Hi to all,
It's more mysql question than php, but I like you more than mysql guys! :)

Let's say I have a table called "orders" and other table called 
"special_orders_instructions".
Logically, one column in "orders" table should be link to 
"special_order_instructions" (foreign key ?) and if that one is checked 
go and grab special instructions after order_id.
But, since "orders" table doesn't have such a column (and I CANNOT add 
it - long story...) I have to check for every order does that order_id 
exists in "special_order_instructions" table. And, if yes - print.
Table "special_order_instructions" has about 25 columns and I have to 
show EVERY ONE. Means, have to use
select * from special_order_instructions...
But, just to check does such an order have any special instruction
$query = mysql_query("select * from special_order_instructions...");
is bad idea. It would be "more" correct
$query = mysql_query("select spec_inst_id from 
special_order_instructions...");
and then
if (mysql_num_rows($query) > 0)

    // Show instructions


Does this make a sense:
$query = mysql_query("select spec_inst_id from 
special_order_instructions...");
if (mysql_num_rows($query) > 0)

    $query = mysql_query("select * from special_order_instructions...");
    while( ... )
    
       // show instructions here...
    



Thanks for any help!

-afan

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


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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