Cross Matching Results

Discussion in 'PHP' started by adamjblakey, Dec 13, 2007.

  1. #1
    Hi,

    I have 2 tables both with a country field in. I am doing a query on the first table to pull out all the results and then i want to do another query on table 2 which checks each result to see if the country field matches any on the loop of table 1.

    
    
    function selects($select) {
     $this->result = mysql_query($select,$this->connection);
     $this->row = mysql_fetch_assoc($select);
     }
    
    
    function getRes() {
     while ($res = mysql_fetch_array($this->result)) {
     $this->reser[] = $res;
       }
     return $this->reser;
      }
    
    
    //Latest 5 load results
    $current = new database;
    $current->selects("SELECT * FROM loads ORDER BY collect_date");
    $cresults = $current->getRes(); 
    
        // assign your db results to the template
        $smarty->assign('cresults', $cresults);
    	
    
    //match results
    $match = new database;
    $match->selects("SELECT * FROM vehicles WHERE region = '$cresults[region]'");
    $matches = $match->getRes();
    $countrows = $match->countrows(); 
    	//Countrows
    	$smarty->assign('countrows', $countrows);
    
    Code (markup):

    HTML Side

     
    {foreach from=$cresults item=cresult name=cresults}
                     {$cresult.to_city} - Matched Results {$countrows} 
      {/foreach}
    
    Code (markup):
    But {$countrows} shows 0 on all the rows, but some of them have 2, 3 matchs.

    Any ideas?

    Cheers,
    Adam
     
    adamjblakey, Dec 13, 2007 IP
  2. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you have the database schema it will be easier, I can't follow what your doing unless I read carefully.
     
    Kalyse, Dec 13, 2007 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    adamjblakey, Dec 13, 2007 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Can anyone help me with this one.. its really confusing me.
     
    adamjblakey, Dec 14, 2007 IP