iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-21-2009, 01:07 PM
WebProWorld New Member
 
Join Date: Jan 2009
Posts: 2
rokkstar RepRank 0
Default Getting AVG rating from separate table help

Hello,

I'm hoping someone might be able to help me. I have a database with two tables, venue and reviews. I am returning all the results of the venue table using the following SQL query:
$query_venue = "SELECT * FROM venue WHERE County = '".$_GET['County']."'";

In the review table I have user reviews of the venues. I want to be able to add the avg rating given to the venue to list of returned records from the above query. The SQL i'm using is the following:
$query_rating = "SELECT ROUND(AVG(reviews.rating)) FROM reviews, venue WHERE reviews.venueName = venue.Name AND reviews.approved = '1' GROUP BY venue.Name";

My PHP to echo the records is as follows:
PHP Code:
<?php do { ?>
     <div class="resultblock">
          <h3><?php echo $row_venue['Name']; ?></h3>
          <div class="resultsaddress">                    
                        
                <ul class="resultsDisplay">
                     <li><?php echo $row_venue['Address1']; ?></li>
                            
                     <?php if ($totalRows_venue 0) {  ?>
                     <li><?php echo $row_venue['Address2']; ?></li>
                     <?php ?>
                              
                     <li><?php echo $row_venue['Town']; ?></li>
                     <li><?php echo $row_venue['County']; ?></li>
                     <li><?php echo $row_venue['Postcode']; ?></li>
               </ul>    
                    
          </div><!--/resultsaddress-->
                    
          <div class="resultsrating"><?php echo $row_rating['ROUND(AVG(reviews.rating))']; ?></div>
                    
          </div>  <!--/resultblock--> 
                    
<?php } while ($row_venue mysql_fetch_assoc($venue)); ?>
However, the problem is that each record gets given the same rating regardless of whether it has one. I thought it might be easier to combine the SQL into one statement and came up with this:

$query_venue = "SELECT venue.ID, venue.Name, venue.Address1, venue.Address2, venue.Town, venue.County, venue.Postcode, ROUND(AVG(reviews.rating)) FROM venue, reviews WHERE County = '".$_GET['County']."' AND reviews.venueName = venue.Name GROUP BY venue.Name";

..but this only returns the records that have an associated rating in the reviews table.

Can anyone help me out with returning all records, and putting the rating of that record (if it has one)?

Any help would be greatly appreciated.

Cheers
Matt
Reply With Quote
  #2 (permalink)  
Old 01-22-2009, 06:10 AM
WebProWorld New Member
 
Join Date: Jan 2009
Posts: 2
rokkstar RepRank 0
Default Re: Getting AVG rating from separate table help

Hello,

Does anyone have any idea with this at all? I'm tearing my hair out with this problem.

Cheers
Matt
Reply With Quote
  #3 (permalink)  
Old 01-24-2009, 09:33 PM
WebProWorld New Member
 
Join Date: Jan 2009
Posts: 1
pantrygrazing RepRank 0
Default Re: Getting AVG rating from separate table help

venue right join review, then perform rollup on results of right join. there are other ways.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate url link edhan Web Programming Discussion Forum 0 02-22-2008 04:03 AM
To separate or not separate... that is the question pdstein Search Engine Optimization Forum 8 11-24-2005 10:19 AM
Table Align to table sysop9999 Graphics & Design Discussion Forum 3 11-10-2005 11:00 AM
Scrolling vs separate pages James Bull Graphics & Design Discussion Forum 11 09-23-2004 01:30 PM
Redirect vs Separate Sites PunkyLZ Search Engine Optimization Forum 3 06-26-2004 07:14 AM


All times are GMT -4. The time now is 12:18 AM.



Search Engine Optimization by vBSEO 3.3.0