Hello,

 

I have two tables:

 

Table2 (listings), columns - listingID, state, preferred, siteAddress,
siteTitle, siteDescription

Table1 (invotes), columns listingID

 

I want to select the listingID of the rows in Table2 where the 'state'
column equals '$st' then count the number of rows in Table1 that have the
same listingID as those selected in Table2. I want to pull the information
from Table2 regardless if there is an entry in Table1 with the same
listingID or not. However, if the listingID is the same in Table1 compared
to Table2 then I want to count the number of rows that have that listing.
More importantly, I need to sort the rows from highest to lowest. 

 

I hope I made sense, this is what I have so far (which will output what I
want but NOT in order of votes ($invotes in my example)

 

 

                                                $query_state = "SELECT
listingID FROM listings WHERE state='$st'"; 

                                                $result_state  =
@mysql_query($query_state);

                                                if
(mysql_num_rows($result_state) > 0) { // if at least one exists

                                                            

                                                            while
($row_state = mysql_fetch_array($result_state, MYSQL_NUM)) {

                                                                         

                                                                        

 
$query_category = "SELECT count(*) as hits FROM 

 
invotes WHERE listingID = '$row_state[0]' ORDER BY hits DESC"; 

                                                                        

                                                                        

 
$result_category  = @mysql_query($query_category);

                                                                        

                                                                        

 
$row_category = mysql_fetch_array($result_category, MYSQL_NUM);

 


 


 
$invotes = $row_category[0];

 


 


 
// get listing information

 
$query_client = "SELECT preferred, siteAddress, siteTitle, siteDescription
FROM listings WHERE listingID='$row_state[0]'"; 

 
$result_client  = @mysql_query($query_client);

 
$row_client = mysql_fetch_array($result_client, MYSQL_NUM);

 

...then start printing our information from Table2

 

 

 

Best regards,

Ryan

 

Reply via email to