graham23s Posted February 1, 2010 Share Posted February 1, 2010 Hi Guys, In a search query on my site i have the basic code setup like this: <?php $s = mysql_query("SELECT * FROM `cpa` WHERE `raw_search` LIKE '%$search%' ORDER BY `raw_search` DESC"); while ($r = mysql_fetch_array($s)) { print $r['link'] . "<br />"; } ?> This prints all the search data in a row, the only thing that groups the data together is the time stamp it was inserted in to the database with. search1 (timestamp1) search1 (timestamp1) search2 (timestamp2) search2 (timestamp2) search2 (timestamp2) what i am trying to do is put a <hr> under the last result to seperate them up a bit on page like: search1 (timestamp1) search1 (timestamp1) _________________ search2 (timestamp2) search2 (timestamp2) search2 (timestamp2) i can't think of way to do it, any help would be appreciated. thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/190491-looping-seperating-data/ Share on other sites More sharing options...
Catfish Posted February 1, 2010 Share Posted February 1, 2010 have a look in SQL manual at 'GROUP BY'. Link to comment https://forums.phpfreaks.com/topic/190491-looping-seperating-data/#findComment-1004803 Share on other sites More sharing options...
JAY6390 Posted February 1, 2010 Share Posted February 1, 2010 Can you give an example of a couple of the rows output? Also, do the search queries all have single words or multiple words? Link to comment https://forums.phpfreaks.com/topic/190491-looping-seperating-data/#findComment-1004804 Share on other sites More sharing options...
graham23s Posted February 1, 2010 Author Share Posted February 1, 2010 Hi Guys The output would be like: site1.com/page1 added on 2010-01-31 23:17:53 site1.com/page2 added on 2010-01-31 23:17:53 site2.com/page1 added on 2010-01-31 23:17:56 site2.com/page2 added on 2010-01-31 23:17:56 site2.com/page3 added on 2010-01-31 23:17:56 they output one after each other, to make them a little better i was trying to seperate them like: site1.com/page1 added on 2010-01-31 23:17:53 site1.com/page2 added on 2010-01-31 23:17:53 -------------------------------------------------------------- <- seperator site2.com/page1 added on 2010-01-31 23:17:56 site2.com/page2 added on 2010-01-31 23:17:56 site2.com/page3 added on 2010-01-31 23:17:56 thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/190491-looping-seperating-data/#findComment-1004908 Share on other sites More sharing options...
JAY6390 Posted February 1, 2010 Share Posted February 1, 2010 <?php $s = mysql_query("SELECT * FROM `cpa` WHERE `raw_search` LIKE '%$search%' ORDER BY `raw_search` DESC"); $last_timestamp = ''; while ($r = mysql_fetch_array($s)) { print $r['link']."<br />"; preg_match('added on \K.*',$r['link'], $out); if($out[0] != $last_timestamp && $last_timestamp != '') echo '<hr />'; $last_timestamp = $out[0]; } ?> Try that Link to comment https://forums.phpfreaks.com/topic/190491-looping-seperating-data/#findComment-1004931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.