adamjblakey Posted December 12, 2007 Share Posted December 12, 2007 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 https://forums.phpfreaks.com/topic/81361-smarty-cross-matching-results/ Share on other sites More sharing options...
adamjblakey Posted December 12, 2007 Author Share Posted December 12, 2007 Can anyone help with this? Link to comment https://forums.phpfreaks.com/topic/81361-smarty-cross-matching-results/#findComment-413146 Share on other sites More sharing options...
lemmin Posted December 12, 2007 Share Posted December 12, 2007 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 https://forums.phpfreaks.com/topic/81361-smarty-cross-matching-results/#findComment-413152 Share on other sites More sharing options...
adamjblakey Posted December 12, 2007 Author Share Posted December 12, 2007 How would i go about doing this as i am unsure? Link to comment https://forums.phpfreaks.com/topic/81361-smarty-cross-matching-results/#findComment-413159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.