Jump to content

Recommended Posts

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

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

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

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

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.