doddsey_65 Posted May 25, 2011 Share Posted May 25, 2011 im trying to run a query which will get posts from the database that have tags similar to the current ones. Unfortunatly the echoed result isnt displaying as it should. $query = $link->query("SELECT t.*, p.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) WHERE t.t_name = '".decode_url($_GET['t_name'])."' LIMIT 1") or die(print_link_error()); $row = $query->fetch(PDO::FETCH_ASSOC); $tag_query = $link->query("SELECT p_name FROM ".TBL_PREFIX."posts WHERE MATCH (p_tags) AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE) ")or die(print_link_error()); $result = $tag_query->fetch(); foreach($result as $key => $value) { echo 'Name = '.$result[$key]['p_name'].'<br />'; } i have done a dump of result and it shows: $ => Array (2) ( ['p_name'] = String(12) "File Updates" ['0'] = String(12) "File Updates" ) but there should only be one item in this array(p_name). I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right. Quote Link to comment https://forums.phpfreaks.com/topic/237454-get-similar-posts/ Share on other sites More sharing options...
btherl Posted May 25, 2011 Share Posted May 25, 2011 That looks like the same column indexed by both name and number. If you refer to it by name consistently you should have no problems. Quote Link to comment https://forums.phpfreaks.com/topic/237454-get-similar-posts/#findComment-1220284 Share on other sites More sharing options...
doddsey_65 Posted May 25, 2011 Author Share Posted May 25, 2011 the problem was this line: $result = $tag_query->fetch(); i should have been using $result = $tag_query->fetchAll(); to loop through the results in the foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/237454-get-similar-posts/#findComment-1220288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.