Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-16-2006, 01:57 PM   #1 (permalink)
franknu
Junior Member
 
Join Date: Jun 2006
Posts: 1
Default Associating Colums and tables

Ok, I have a database and i want to associate colums to be display when a user type in something in categories. I created a diffrent table for almost everything. I was just wondering if i have to create a full table with the information i want to associate or if it is ok to have in diffrent tables

here is the code


PHP Code:
<?php 
print_r
($_POST); 

if(isset(
$_POST['submit'])) 


$host "localhost"
$username "localhost"
$password "abc123"
$database "contacts"

if(isset(
$_POST['Categories'])) 

    
$Categories trim(addslashes($_POST['Categories'])); 

else 

    echo 
'No Category Passed'
    exit; 


$db mysql_connect($host$username$password); 
mysql_select_db($database); 
$query "SELECT * FROM Categories WHERE Categories LIKE '%$Categories%'"
$result mysql_query($query) or die (mysql_error()); 
$num_result mysql_num_rows($result); 

if(
$num_result == 0

    echo(
"No Results found."); 
    exit; 


echo 
"<p>Number of business found: $num_result </p>"
while(
$row mysql_fetch_assoc($result)) 

     echo 
'<p><strong>Business Name (' stripslashes($row['BusinessName']) . ')'
     echo 
'(' $row['slogan'] . ')</strong><br />'
     echo 
'Address (' stripslashes($row['BusinessAddress']) . ')<br />'
     echo 
'State (' stripslashes($row['make']) . ')<br />'
     echo 
'City (' stripslashes($row['type']) . ')<br />'
     echo 
'Tel (' stripslashes($row['tel']) . ')<br /></p>'


?>
this is what i am displaying

Array ( [make] => Massachusetts [type] => Lawrence [Categories] => printing [textfield] => [submit] => Search )
Number of business found: 1

BusinessName ()()
Address ()
State ()
City ()
Tel ()

i have a business name MASS AD
Address 19 Central St
In MAKE MASSACHUSETTS
TYPE LAWRENCE
978.327.5139

how can i make like that for now it is just showing that i have a category Name "Printing"
franknu is offline   Reply With Quote
Sponsored Links
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
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 01:55 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums