Jump to content

PHP Recursion, I think?


jmholl5

Recommended Posts

So I pretty new to PHP and MySQL, but I've been doing pretty well at getting what I want done for this website I volunteered to make, but now I've come to something that I don't know how to approach, and I think recursion is the answer.

 

Here is my table structure:

 

| id | class | playername |award |

 

The thing is there are some players with 1 award and some with 5. So the player with 5 awards has 5 separate entries in the table, one for each award. This is all fine, but I'd like to display the data in this way:

 

<h3>class</h3>

<h4>1st playername for above class</h4>

      <ul>

          <li>1st award for above playername</li>

          <li>2nd award for above playername(if it exists)</li>

        (continue to list all awards in own list item until complete)

      </ul>

<h4>2nd playername for above class</h4>

      <ul>

          <li>1st award for above playername</li>

          <li>2nd award for above playername(if it exists)</li>

        (continue to list all awards in own list item until complete)

      </ul>

 

Then repeat for all the data in the table. Basically I only want to display each class once, then all the playernames for that class, and then all the awards for each playername under each one.

 

Just looking for advice on whether or not this is possible and if so how to do it. I'm also open to changing my table structure if that would make it easier. I tried looking through PHP recursion tutorials but couldn't figure it out. Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/158414-php-recursion-i-think/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.