Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:41:44+00:00 2026-06-11T07:41:44+00:00

I really couldn’t find a good way to title this so I apologize if

  • 0

I really couldn’t find a good way to title this so I apologize if it’s misleading, but what I’m trying to do is I have badges that players earn and I want them to be able to click on the badges and based on the badge they click get a different description to load using jquery. I already have it partly working, but the problem I’m having is it only gets the last badge’s info. I know why it does this (I think, php is loaded first in page, and it’d need to be an array. Or maybe I just sound really dumb, haha) Here is what my code is so far:

    <table id="table-profile" width="78%">
  <tr>
    <td><h3><?php echo "$usernameprofile";?>'s Badges (work in progress!!!!!!!) |  <a href="#">View All</a></h3></td>
  </tr>
  <tr>
    <td><?  
 $sqlbadges = mysql_query("SELECT * FROM membersbadges WHERE username='$usernameprofile' LIMIT 8 
 ");
 $checkbadges = mysql_num_rows($sqlbadges);
 if($checkbadges == "0"){
     echo "User is currently badgeless";
 }else{
?>
<table width="100%">
<?php
$tableCount = 0;
    $tableRowOpen = false;
    while($rowbadge = mysql_fetch_assoc($sqlbadges)) { 
    $bid = $rowbadge['badgeid'];

    $getbadge = mysql_query("SELECT * FROM badges WHERE id='$bid'");
while($rowbadge2 = mysql_fetch_assoc($getbadge)){
$badgeid = $rowbadge2['id'];    
$badgename = $rowbadge2['name'];
$badgedesc = $rowbadge2['description'];
$badgereward = $rowbadge2['reward'];
$badgerequirements = $rowbadge2['requirements'];
$badgepic = $rowbadge2['image'];
$date = strftime("%b %d, %Y", strtotime($rowbadge2['date']));

}
        if($tableCount == 0){
            echo "<tr>";
            $tableRowOpen = true;
        }
        echo"<td width='25%'>";
        echo  "<badge".$badgeid.">
<img src=\"http://my.iheff.net/images/badges/".$badgepic.".png\" border=2 alt=\"
        " . $row["name"] . "\" height=40px width=40px></a></badge".$badgeid.">" ;

        echo"<br/><br/></td>";
        if($tableCount + 1 == 4){
            $tableCount = 0;
            echo "</tr>";
            $tableRowOpen = false;
        }
        else{
            $tableCount++;
        }

    }
    if($tableRowOpen){
        echo "
</tr>
";
    }
    echo"
    <table id='badgeinfo".$badgeid."' style='display:none' width='80%' border='0' cellspacing='5' cellpadding='10'>
  <tr>
    <th colspan='2' scope='col'>".$badgename."</th>
    </tr>
  <tr>
    <td>Description:</td>
    <td>".$badgedesc."</td>
  </tr>
  <tr>
    <td>Reward:</td>
    <td>+".$badgereward." Experience</td>
  </tr>
</table>
    ";
?>
</table>
<?
 }
 ?></td>
  </tr>

</table>

<script>
$("badge<?php echo "$badgeid"?>").click(function () {
$("#badgeinfo<?php echo "$badgeid"?>").toggle("slow");
});    
</script>

Sorry for the messy code, I’m nowhere near a php whiz. But, I will appreciate any help. Thanks!

Here’s an example page if you want to see how the page looks live. http://my.iheff.net/profile.php?id=1637

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:41:46+00:00Added an answer on June 11, 2026 at 7:41 am

    It looks like you’re closing the while loop too quickly. (It’s looping through all the records, and assigning them, but not rendering them.) So put all the badge rendering logic inside this loop:

    while($rowbadge2 = mysql_fetch_assoc($getbadge)){
        $badgeid = $rowbadge2['id'];    
        $badgename = $rowbadge2['name'];
        $badgedesc = $rowbadge2['description'];
        $badgereward = $rowbadge2['reward'];
        $badgerequirements = $rowbadge2['requirements'];
        $badgepic = $rowbadge2['image'];
        $date = strftime("%b %d, %Y", strtotime($rowbadge2['date']));
    
        // render the row here
    }
    

    To fix the Javascript issue, you could add the Javscript inside the loop, but it’s probably better to add attributes to the badge tags:

    echo  "<badge".$badgeid." data-type='badge' data-id='".$badgeid."'">"
    

    That way you can use a single (static) block of Javscript to construct the click events:

    // select all the badge tags
    $("[data-type=badge]").each(function() {
        // get the id for the current badge
        var thisId = $(this).attr('data-id');
        $(this).click(function() {
            $("#badgeinfo" + thisId).toggle("slow");
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really couldn't figure out a good title for this question, but I have
I have been looking around for an answer to this, but couldn't really find
I have searched this but really I couldn't find the exact answer for .asmx
This is a simple question really (but I couldn't seem to find the answer
This is a really simple problem, but I couldn't find a solution anywhere. I'm
I've been thinking of this question very long, but really couldn't find the answer
Though this question has been asked several times but I really couldn't find any
I'm sorry for asking this sort of questions, but I really couldn't find the
I have this htaccess code RewriteRule ^/([uge])/([^/]+)$ /$1/$2/ But I couldn't really understand what
Sorry if the title is misleading, but I really couldn't think of anything better.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.