Current location: Hot Scripts Forums » Programming Languages » PHP » Joining tables and fetch_assoc


Joining tables and fetch_assoc

Reply
  #1 (permalink)  
Old 10-29-08, 05:20 PM
user1001 user1001 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Joining tables and fetch_assoc

Hi all,

First of all, I know this is very long, however it's just to show you what I've got,
and what I want, the questions are at the end.

I have two Tables:

Table rating
|- Id
|- product_name
|- good
|- bad
|- rating_id

// this table is for the details

Table rating_ids
|- Id
|- rating_name

// this is just to have different rating categories..

for example:
i would like to output boxes like:

rating name
---------------------------------
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad

rating name2
---------------------------------
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad

rating name3
---------------------------------
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad

etc...

and I have the following code:

Code:
<?php
//default connection files
include 'includes/config.php';
include 'includes/dbconn.php';

$query = "	SELECT *
			FROM rating";


$result = mysql_query($query);

//default database closing file
include 'includes/closedb.php';

//table start
echo '
<table border="0" cellspacing="1px">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Rating</th>
    </tr>
';

//table content
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	$total = $row['good']+$row['bad'];
	$percent_g = round(($row['good']/$total)*100);
	$percent_b = round(($row['bad']/$total)*100) ;
	echo "  <tr class=\"row" .$rowclass. "\">\n";
	echo "      <td>{$row['Id']}</td>\n" .
	     "      <td>{$row['product_name']}</td>\n" .
	     "      <td>{$row['good']}</td>\n";
	echo "  </tr>\n";
}

//table end
echo '</table>';


?>
what this code will do is:

output everything at once...
without categorising them seperately
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad
prduct name | good | bad

Questions
what is the concept of joinging these two tables?
what would I need to use: php or mysql or both?
how will fetch_assoc work with this?



thanks in advance...

Last edited by user1001; 10-29-08 at 05:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-30-08, 06:03 PM
user1001 user1001 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
wow 49 views and no replies
maybe Nobody understood what I need help on?
any one can help on this...

maybe I can do this:

while (mysql_fetch_array (query1 assoc)){

print headers...

while (mysql_fetch_array (query2 assoc)){
if(id_something == id2_something){

print content...

}
}
}


???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump


All times are GMT -5. The time now is 06:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.