View Single Post
  #1 (permalink)  
Old 10-29-08, 04: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 04:40 PM.
Reply With Quote