hackalive Posted March 28, 2010 Share Posted March 28, 2010 Hi guys, so I have a DB which has a table called article, it has a field called group (which is an INT from 0 to 9) now I need when displaying content on PHP page for the articles to be in their groups, so all 0s to echo one after the other then the group 1 etc Any ideas on how to do this? I have already got the mysqli code to get all the articles now just need to do this sort and echo Thanks in advance for all and any help Link to comment https://forums.phpfreaks.com/topic/196756-grouping/ Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 someone must have done this before Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1032943 Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 any ideas guys, I really need to solve this Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1032960 Share on other sites More sharing options...
sasa Posted March 28, 2010 Share Posted March 28, 2010 add ORDER BY `group` to the end of your query Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1032977 Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 okay I guess I should be more specific, In a PHP file I have something like this "<div id="header"><PL1></header><div id="content"><PL2></div>" now I need to group based on the INT 0 to 9 and then relate it to the relevant PL# so PL0 is 0 etc so I end up with $1, $2, etc and then can do a replace so <PL1> becomes $1 any help on how to do this would be much appreciated Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1032989 Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 so basically I need a way to add several records from a DB that have the same "position" INT and join them into one variable relative eg $1 etc thanks Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033005 Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033012 Share on other sites More sharing options...
hackalive Posted March 28, 2010 Author Share Posted March 28, 2010 bump Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033269 Share on other sites More sharing options...
hackalive Posted March 29, 2010 Author Share Posted March 29, 2010 someone please........ Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033367 Share on other sites More sharing options...
trq Posted March 29, 2010 Share Posted March 29, 2010 If you want help you need to post some relevant code. Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033369 Share on other sites More sharing options...
hackalive Posted March 29, 2010 Author Share Posted March 29, 2010 I have no idea where to get started; here i what I want to do In a PHP file I have something like this "<div id="header"><PL1></header><div id="content"><PL2></div>" now I need to group based on the INT 0 to 9 and then relate it to the relevant PL# so PL0 is 0 etc so I end up with $1, $2, etc and then can do a replace so <PL1> becomes $1 Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033370 Share on other sites More sharing options...
trq Posted March 29, 2010 Share Posted March 29, 2010 A very simple (and untested) example. $sql = "SELECT data FROM fld ORDER by `group`"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $group = ''; while ($row = mysql_fetch_object($result)) { // if group different to current create a new div. if ($row->group != $group) { echo "<div id='PL{$row->group}'>"; } // echo data within <p></p> tags. echo "<p>{$row->data}</p>"; // if group different to current close div & set to current. if ($row->group != $group) { echo "</div>"; $group = $row->group; } } } } Link to comment https://forums.phpfreaks.com/topic/196756-grouping/#findComment-1033372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.