Jump to content

Smarty Cross Matching Results


adamjblakey

Recommended Posts

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);

 

 

HTML Side

 

 
{foreach from=$cresults item=cresult name=cresults}
                 {$cresult.to_city} - Matched Results {$countrows} 
  {/foreach}

 

But {$countrows} shows 0 on all the rows, but some of them have 2, 3 matchs.

 

Any ideas?

 

Cheers,

Adam

Link to comment
Share on other sites

I don't even see the loop where you compare the two queries, but if you are trying to do what I think you are trying to do, it would probably be easier with a JOIN clause. You could probably even do it without the join clause and just query both tables in your query.

 

Here is the JOIN documentation:

http://dev.mysql.com/doc/refman/5.1/en/left-join-optimization.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.