Page 1 of 1

Select statement

Posted: Thu May 18, 2006 2:56 pm
by faris10
Hi All,
I have 2 tables producst and products_description
I want to use select statement to select products.Productname,products.URL,products_description.description where products.products_id=products_description.products_id
There is something wrong with my statemnet in PHP , can anyone reply with correct syntax. I'm using PHP 5 and mysql 5
Thanks

Posted: Thu May 18, 2006 3:15 pm
by RobertGonzalez

Code: Select all

<?php
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id";
?>

Posted: Thu May 18, 2006 3:51 pm
by faris10
Everah wrote:

Code: Select all

<?php
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id";
?>
Thanks I see where my mistake was

Posted: Thu May 18, 2006 7:50 pm
by faris10
Everah wrote:

Code: Select all

<?php
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id";
?>
What if I do not want to include all the products where product name is empty ?

Posted: Thu May 18, 2006 10:01 pm
by RobertGonzalez
faris10 wrote:What if I do not want to include all the products where product name is empty ?
Lets use some logic...

Code: Select all

<?php
// Get all products
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id";
?>
Now lets say we want only products whose description has something in it

Code: Select all

<?php
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id
        AND products_description.description <> ''
        # or you can use...
        #AND products_description.description IS NOT NULL";
?>
Can you apply this logic to other criteria?

Posted: Thu May 18, 2006 11:25 pm
by faris10
Now lets say we want only products whose description has something in it

Code: Select all

<?php
$sql = "SELECT products.Productname, products.URL, products_description.description 
        FROM products, products_description 
        WHERE products.products_id = products_description.products_id
        AND products_description.description <> ''
        # or you can use...
        #AND products_description.description IS NOT NULL";
?>
Can you apply this logic to other criteria?[/quote]
AND products_description.description <> ''
This works, the other one no. I will go back and read more in book to get more familiar with what's happening.

Posted: Fri May 19, 2006 12:28 am
by RobertGonzalez
If the IS NOT NULL syntax is not doing what you'd expect, it might be how your fields are set up. If the first one works, use that as it achieves essentially the same thing.