View Single Post
Old 06-17-2006, 08:23 PM   #2 (permalink)
etono
Moderator
 
Join Date: May 2006
Posts: 86
Default Re: Associating Colums and tables

I think I know what you mean. So, basically their is categories in a category table, their are Businesses with thier addresses in another table? Perhaps you may want to create a new field in your business table which is category_id which would be the primary key of the category table. Then you would LEFT JOIN the businesses table on the category_id.

PHP Code:
<?php
//assume connection to db
$sql "SELECT * FROM categories
          LEFT JOIN businesses ON (categories.category_id = businesses.category_id)
          WHERE category.category_name LIKE %$clean_category%"
;
$result mysql_query$sql );
while( 
$row mysql_fetch_array$resultMYSQL_ASSOC ) ) {
    
//encode or strip slashes for output
    
echo "Name: {$row['business_name']}";
    echo 
"Address: {$row['business_address']}";
    
//etc
}
?>
__________________
Jeremy Moseley
My Links: Design Related Blog | Personal Website | Portfolio
etono is offline   Reply With Quote
Sponsored Links