Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading different descriptions within PHP array
    primarykey
    data
    text
    <p>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:</p> <pre><code> &lt;table id="table-profile" width="78%"&gt; &lt;tr&gt; &lt;td&gt;&lt;h3&gt;&lt;?php echo "$usernameprofile";?&gt;'s Badges (work in progress!!!!!!!) | &lt;a href="#"&gt;View All&lt;/a&gt;&lt;/h3&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;? $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{ ?&gt; &lt;table width="100%"&gt; &lt;?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 "&lt;tr&gt;"; $tableRowOpen = true; } echo"&lt;td width='25%'&gt;"; echo "&lt;badge".$badgeid."&gt; &lt;img src=\"http://my.iheff.net/images/badges/".$badgepic.".png\" border=2 alt=\" " . $row["name"] . "\" height=40px width=40px&gt;&lt;/a&gt;&lt;/badge".$badgeid."&gt;" ; echo"&lt;br/&gt;&lt;br/&gt;&lt;/td&gt;"; if($tableCount + 1 == 4){ $tableCount = 0; echo "&lt;/tr&gt;"; $tableRowOpen = false; } else{ $tableCount++; } } if($tableRowOpen){ echo " &lt;/tr&gt; "; } echo" &lt;table id='badgeinfo".$badgeid."' style='display:none' width='80%' border='0' cellspacing='5' cellpadding='10'&gt; &lt;tr&gt; &lt;th colspan='2' scope='col'&gt;".$badgename."&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Description:&lt;/td&gt; &lt;td&gt;".$badgedesc."&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Reward:&lt;/td&gt; &lt;td&gt;+".$badgereward." Experience&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; "; ?&gt; &lt;/table&gt; &lt;? } ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script&gt; $("badge&lt;?php echo "$badgeid"?&gt;").click(function () { $("#badgeinfo&lt;?php echo "$badgeid"?&gt;").toggle("slow"); }); &lt;/script&gt; </code></pre> <p>Sorry for the messy code, I'm nowhere near a php whiz. But, I will appreciate any help. Thanks! </p> <p>Here's an example page if you want to see how the page looks live. <a href="http://my.iheff.net/profile.php?id=1637" rel="nofollow">http://my.iheff.net/profile.php?id=1637</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload