0

I'm developing a Meet the Team page for my website. Here's how it looks so far (http://prntscr.com/gynyrj).

As you can see, it's in descending order. But, what I'm trying to achieve is so that each new level would go onto the next row. e.g. administrators level 7 at the top, administrators level 6 on the next row, administrators level 5 on the next and so on..

Something like this (http://prntscr.com/gyo1pc)

$query = $con->prepare("SELECT * from playerdata WHERE pAdmin >= 1 ORDER BY 
`pAdmin` DESC");
$query->execute();

while($data = $query->fetch())
{
    ...panel code
}

Regards,

Daniel

  • 2
    I'm not sure what you're asking. It looks like this is a layout issue, not a query issue. – tmwoods Oct 17 '17 at 20:23
  • @tmwoods I didn't say it was a query issue. Anyway, I think a loop is required to loop through each level and place them onto a new row? – Danny Barbosa Oct 17 '17 at 20:41
  • @DannyBarbosa You think a loop is required to loop through data? I'd say your pretty spot on, and what you have looks correct to me so far. – GrumpyCrouton Oct 17 '17 at 20:42
  • @GrumpyCrouton What I have so far is only ordering the staff-panels in descending order. I want only one row to contain a certain level. For example, the top row would contain administrators level 7, the second row of panels would contain administrators level 6 and so on... – Danny Barbosa Oct 17 '17 at 20:45
  • What is `pAdmin`, is that what holds the administrator level? – GrumpyCrouton Oct 17 '17 at 20:46
  • Yes, pAdmin is the administrator level. – Danny Barbosa Oct 17 '17 at 20:46
  • 1
    @DannyBarbosa What I would recommend is checking out the answers here https://stackoverflow.com/questions/46490260/converting-flat-array-into-an-array-grouped-by-categories - basically what you want to do is group all of your team members by their administrator level, then you will have a multi-dimensional array that will have the administrator level has the key, and several sub-arrays under each of those that contains the information about your team members. Then you just loop through the array for the administrator level, and have a sub loop to list the team members. – GrumpyCrouton Oct 17 '17 at 20:48
  • @GrumpyCrouton Still not quite sure how to do it. I've read through the topic. Sorry hah, I'm not the best when it comes to php. Any other suggestions? – Danny Barbosa Oct 17 '17 at 21:26

1 Answers1

1

Here's one possible solution. Create a 2D array that stores the $data arrays in your loop, using pAdmin as the first dimension's key:

$query = $con->prepare("SELECT * FROM `playerdata` WHERE `pAdmin` >= 1 ORDER BY `pAdmin` DESC");
$query->execute();

$playersByAdminLevel = array();

while($data = $query->fetch()) {
    $adminLevel = $data['pAdmin'];
    $playersByAdminLevel[$adminLevel][] = $data;
}

You can now do a nested loop over the $playersByAdminLevel array:

foreach($playersByAdminLevel as $players) {
    foreach($players as $player) {
        // $player['name'] etc.
    }
    echo '<br>\n'; // ... or whatever html you need to start the next row
}
tobiv
  • 821
  • 1
  • 8
  • 20
  • Works like a charm! Thanks for the help! I've got one more thing though, if you don't mind me asking. How can I centre the panels in the middle of the page? (like this - http://prntscr.com/gyph6u) – Danny Barbosa Oct 17 '17 at 22:19
  • You should create a new question for that; post the relevant HTML and styles. – tobiv Oct 18 '17 at 08:51