girardz Posted October 6, 2009 Posted October 6, 2009 Im trying to create a page that shows all the NPC's in my game along with each NPC's stats, weapons and armor equiped. I also want to show the number of times each NPC has been beaten. I was going to post it here when completed but I need a little help finishing it, lol I cant get the query for the count to show. NPCstats.php <?php include "sglobals.php"; { print " <table width=100% border=1 class=table> <tr align=center> <td class=h>ID</td> <td class=h>NPC Username</td> <td class=h>Level</td> <td class=h>Unit</td> <td class=h>Beaten</td> <td class=h>STRENGHT</td> <td class=h>AGILITY</td> <td class=h>GRUARD</td> <td class=h>PRI</td> <td class=h>SEC</td> <td class=h>ARM</td> </tr>"; $q=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.user_level = 0 "); while($r=$db->fetch_row($q)) print "<tr align=center> <td>{$r['userid']}</td> <td align=left>{$r['username']}</td> <td>{$r['level']}</td> <td>{$r['location']}</td> <td>COUNT CODE HERE</td> <td>{$r['strength']}</td> <td>{$r['agility']}</td> <td>{$r['guard']}</td> <td>{$r['equip_primary']}</td> <td>{$r['equip_secondary']}</td> <td>{$r['equip_armor']}</td> </tr>"; } print "</table>"; $h->endpage(); ?> Any help finishing this would be greatly appriciated Quote
girardz Posted October 6, 2009 Author Posted October 6, 2009 I had: [mysql]$count = mysql_query("SELECT * FROM challengebots WHERE cb_npcid=".$user['userid']) or die(mysql_error()); $count = mysql_fetch_assoc($count);[/mysql] but I couldnt get it to work. Quote
Danny696 Posted October 6, 2009 Posted October 6, 2009 From the old battle tent $a=$db->query("SELECT count(*) FROM challengesbeaten WHERE npcid=$v"); $times=$db->fetch_single($a); Quote
girardz Posted October 6, 2009 Author Posted October 6, 2009 From the old battle tent $a=$db->query("SELECT count(*) FROM challengesbeaten WHERE npcid=$v"); $times=$db->fetch_single($a); tried that it gives me: QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Query was SELECT count(*) FROM challengesbeaten WHERE npcid= Quote
Danny696 Posted October 6, 2009 Posted October 6, 2009 $q=$db->query("SELECT cb.*,u.*,c.npcid,cy.cityname FROM challengebots cb LEFT JOIN users u ON cb.cb_npcid=u.userid LEFT JOIN challengesbeaten c ON c.npcid=u.userid AND c.userid=$userid LEFT JOIN cities cy ON u.location=cy.cityid"); while($r=$db->fetch_row($q)) { $earn=$r['cb_money']; $v=$r['userid']; $a=$db->query("SELECT count(*) FROM challengesbeaten WHERE npcid=$v"); $times=$db->fetch_single($a); and print"$times"; Quote
girardz Posted October 7, 2009 Author Posted October 7, 2009 OK Thanks that works But now I have: $q=$db->query("SELECT cb.*,u.*,c.npcid,cy.cityname FROM challengebots cb LEFT JOIN users u ON cb.cb_npcid=u.userid LEFT JOIN challengesbeaten c ON c.npcid=u.userid AND c.userid=$userid LEFT JOIN cities cy ON u.location=cy.cityid"); while($r=$db->fetch_row($q)) { $v=$r['userid']; $a=$db->query("SELECT count(*) FROM challengesbeaten WHERE npcid=$v"); $times=$db->fetch_single($a); $q2=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.user_level = 0 "); while($stat=$db->fetch_row($q2)) I currently have 16 NPC's in my game and its showing the same NPC 16 times then shows the next NPC 16 times and so on ???????????? the stats and other info are correct except the stats go in the correct order for the 16 and then start over on the next 16. If that makes any sence...lol :huh: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.