Jump to content

widget

Members
  • Posts

    148
  • Joined

  • Last visited

Everything posted by widget

  1. I dont think thats quite what I wanted. What that did was display each pet id with a number following, going from 1 to 100 Maybe if I explain the situation better... I have a pet site I am making and users can purchase books to read to their pets. When a book has been read the pets id number along with the items id number are placed into the table. What I would like to display is a list of what pet has read the most books from highest to lowest with a limit of 100. This below code is the only code I've been able to use without getting errors but unfortunately it doesnt display the pets from books read highest to lowest and displays the pet id from highest to lowest instead. <?php $query = "SELECT DISTINCT `pet_id`, COUNT(`pet_id`) AS amount FROM `read2` GROUP BY `pet_id` ORDER BY `pet_id` ASC"; $result= mysql_query($query) or die ("Error in query " . mysql_error()); //whats the error?? while($row = mysql_fetch_assoc($result)) { $username = $row['pet_id']; $number = $row['amount']; echo $username . ' - ' . $number . '<br />'; } ?> Out put 37057 - 48 37061 - 1 37139 - 4 37195 - 1 37261 - 1 37263 - 5 37275 - 2 37320 - 3 37321 - 3 37323 - 61 37329 - 48 37359 - 41 37384 - 1 37391 - 2 37396 - 1 37454 - 1 37460 - 2 37465 - 1 37481 - 1 37482 - 1 37484 - 2 37486 - 1 37501 - 3 37506 - 16
  2. Thanks but I just tried that too and its at least showing the data but still not in order of books read. Current code <?php $query = "SELECT DISTINCT `pet_id`, COUNT(`pet_id`) AS amount FROM `read2` GROUP BY `pet_id` ORDER BY `pet_id` ASC"; $result= mysql_query($query) or die ("Error in query " . mysql_error()); //whats the error?? while($row = mysql_fetch_assoc($result)) { $username = $row['pet_id']; $number = $row['amount']; echo $username . ' - ' . $number . '<br />'; } ?>
  3. I tried that and now get this error Error in query 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 'ORDER BY `pet_id` ASC' at line 1
  4. Why 2 queries? No idea - I was just following a code example I found via google. I tried your code and get this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/chicka/public_html/books_high_scores.php on line 23 line 23 is while($row = mysql_fetch_assoc($result))
  5. Im creating a high score table. Using php and mysql Table name read2 2 rows - pet_id and item_id <? $first_query = mysql_query('SELECT DISTINCT `pet_id` FROM `read2`'); while($each = mysql_fetch_array($first_query)) { // while loop to go through all the usernames $new_query = ('SELECT * FROM `read2` WHERE `pet_id` = \'' . $each['pet_id'] . '\' '); $sql = mysql_query($new_query); $username = $each['pet_id']; $number = mysql_num_rows($sql); echo $username . ' - ' . $number . '<br />'; } ?> Result 37359 - 31 37329 - 48 37484 - 2 37482 - 1 37263 - 5 37057 - 47 37501 - 3 37507 - 6 37509 - 1 37516 - 1 37481 - 1 37520 - 3 37885 - 1 37323 - 15 37668 - 55 I need it to display the data sorted from the highest number (left column) to lowest with a limit of say 100. I've tried adding in ORDER BY `pet_id` ASC LIMIT 0, 100 but I just get errors.
  6. Ok Ive got it outputting a count of how many times a pet_id is in the table but cannot get it to do it in order of highest to lowest. If I place ASC LIMIT 0, 100 anywhere i get errors. <? $first_query = mysql_query('SELECT DISTINCT `pet_id` FROM `read2`'); while($each = mysql_fetch_array($first_query)) { // while loop to go through all the usernames $new_query = 'SELECT * FROM `read2` WHERE `pet_id` = \'' . $each['pet_id'] . '\''; $sql = mysql_query($new_query); $username = $each['pet_id']; $number = mysql_num_rows($sql); echo $username . ' - ' . $number . '<br />'; } ?> RESULT 37359 - 31 37329 - 48 37484 - 2 37482 - 1 37263 - 5 37057 - 47 37501 - 3 37507 - 6
  7. Ive tried the following code aswell but get an error <? $first_query = mysql_query('SELECT DISTINCT `pet_id` FROM `read2`'); while($each = mysql_fetch_array($first_query)) { // while loop to go through all the usernames $new_query = 'SELECT * FROM `read2` WHERE `pet_id` = \'' . $each['item_id'] . '\''; $sql = mysql_query($new_query); $username = $each['item_id']; $number = mysql_num_rows(mysql_query($sql)); echo $username . ' - ' . $number . '<br />'; } ?> [code] [/code]
  8. Does anyone know some 3D style chats that are free and easy to use?
  9. Using mysql and php TABLE id item_id pet_id game id is auto increment items id is the item number of the book thats been read pet_id is the pet id number or the pet that read the book game is the game number (always 1) TABLE EXAMPLE id item_id pet_id game 39 30892 37057 1 40 30892 37263 1 41 30975 37329 1 42 30976 37329 1 43 30989 37329 1 44 30997 37329 1 45 30999 37329 1 What I need to do is create a high scores list showing the pet_id and how many books its read. Could someone help me out with the code to do this? My current useless code is <? $x = 0; $query = mysql_query("SELECT pet_id FROM read2"); $num_rows2 = mysql_num_rows($query); while ($array = mysql_fetch_array($query)) { echo "<p align=center>$num_rows2</b></font></p></td>"; $x++; } print "</table></center>"; ?> which just displays the total number of entries in the table.
  10. Ok solved for those who ever need it heres the code <? $sql = mysql_query("SELECT * FROM avatar_blank WHERE user_name = '$username' AND avatar_name = 'ecard'"); $result = mysql_num_rows($sql); if($result=="0") { $sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$username','ecard')"); if(!$sql) { echo "Error performing query: ".mysql_error(); } else { echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/avatars/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; } } ?>
  11. Ok now tearing my hair out!!! Im desperate here $sql = mysql_query("SELECT * FROM avatar_blank WHERE username = '$username' AND avatar_name = 'ecard'"); $result = mysql_num_rows($sql); if($result=="0") { $sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$username','ecard')"); if(!$sql) { echo "Error performing query: ".mysql_error(); } else { echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/images/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; } } ERROR Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/chicka/public_html/cards/processCompose.php on line 34 I always get this num rows error - is there another option?
  12. I just went into phpmyadmin and found it was posting the information to the database but not taking the $username. Thats something im going to have to work out from SESSION or something
  13. ok now im trying this after reading many tutorials and examples... $sql = mysql_query("SELECT * FROM avatar_blank WHERE username = '$username' AND avatar_name = 'ecard'"); $result = mysql_num_rows($sql); if($result=="0") { exit; } else { $sql = mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$user_name','ecard')"); if(!$sql) { echo "Error performing query: ".mysql_error(); } else { echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=#ffffff><tr><td><img src=/images/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations $username</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; } } I get the error... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/chicka/public_html/cards/processCompose.php on line 34
  14. Site uses php and mysql. I have an avatar system where certain avatars are locked until the user unlocks them by going to certain pages of the site. So far ( being the newb I am ) I only know how to INSERT data from a form. Is there a way to do it on page load or similar? I also need it to first check if the data already exists and if not it inserts the data and then displays a message to the user that they have unlocked the avatar. ( not working ) The current code is... $query = mysql_query("SELECT * FROM avatar_blank WHERE 'user_name' = '$username' AND 'avatar_name' = 'ecard'"); $num = mysql_numrows($query); if($num < 1){ mysql_query("INSERT INTO avatar_blank (user_name, avatar_name) VALUES ('$user_name','ecard')"); echo "<table width=300 border=1 cellpadding=4 cellspacing=0 bordercolor=#000000 bgcolor=white><tr><td><img src=/images/avatars/ecard.gif width=80 height=80 hspace=10 align=left><font color=#FF3399 size=3 face=Arial, Helvetica, sans-serif><b>Congratulations</b></font><font size=2 face=Arial, Helvetica, sans-serif><br><br>You can now use ECard as an avatar on the chat forum </font></td></tr></table>"; }
  15. Hi, my site uses mysql and php. I would like to set up an avatar system ( I have one already but its not working properly) The deal is... There will be default avatars that all users can use and certain ones they will have to unlock in order to use them. What should my database table setup be? One for their currently displayed avatar? One for a list of all avatars? One for a list of avatars available to that person? Anyone know a good guide etc for this or can offer some helpful information.
  16. Hi, I have a website thats using mysql and php Can you recommend a free chat program that I can easily integrate with my current members table for username and password. When I say easily, I mean easily as Im a somewhat newb. Thank you
  17. Seems no1 really knows the answer to this one. I've googled it and none of it makes much sense
  18. Hi, I need to insert data into a table but only if it doesnt already exist. I have tried numerous ways including counting rows and nothing works so help desperately needed here. ??? I have a form that submits the information to this page and then redirects back to the form page with the $errorMessage but for the life of me, it keeps on duplicating the data. $query = fetch("SELECT * FROM avatar_blank WHERE `user_name` = '$userid' AND `avatar_name = 'default'"); if($query[avatar_name] == "default"){ $errorMessage = "You+already+have+that+avatar!"; header("Location: avatar.php?&error=$errorMessage"); } else mysql_query("INSERT INTO avatar_blank (user_name , avatar_url, avatar_name) VALUES ('$userid','$avatar_url','$avatar_name')"); $errorMessage = "You+now+have+a+$avatar_name+avatar!"; header("Location: avatar.php?&error=$errorMessage"); ?> Any help is appreciated Here is another example Ive tried without all the values added $query = mysql_query("SELECT * FROM avatar_blank WHERE `user_name` = '$userid' AND `avatar_name = ''"); $num = mysql_numrows($query); if($num < 1){ INSERT INTO `avatar_blank` ( `user_name` , `avatar_url` , `avatar_name` ) VALUES ( '$userid', '', '' ); }
  19. Ok thank you, I'll give it a go.
  20. Ok heres the deal... I'm using php and mysql for a virtual pet site Im making. My problem.... Items available in a user shop all load on the one page. I need it to only display say 80 items at a time. Here is the code. <?php /* User-run Shops (usershop.php) */ $page_title = "User-run Shops"; $rank_check = 1; include "header.inc.php"; print "$openHTML"; $find_owner = fetch("SELECT id,rank FROM members2 WHERE username = '$user' AND game = '$game'"); $find_shop = fetch("SELECT * FROM usershops2 WHERE owner = '$find_owner[id]' AND game = '$game'"); if ($find_owner[rank] == 0) { die("<table width=100% border=1 cellpadding=4 cellspacing=0 bordercolor=#CCCCCC bgcolor=#FFFFFF> <tr> <td><p align=center class=error>This user has been suspended. <script type=\"text/javascript\"><!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 468; google_ad_height = 60; google_ad_format = \"468x60_as\"; google_ad_type = \"text_image\"; //2007-05-15: users_shop google_ad_channel = \"7041872983\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script></p></td> </tr> </table> $closeHTML"); } if (!$find_shop[id]) { die("<table width=100% border=1 cellpadding=4 cellspacing=0 bordercolor=#CCCCCC bgcolor=#FFFFFF> <tr> <td>This user does not have a shop.<script type=\"text/javascript\"><!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 468; google_ad_height = 60; google_ad_format = \"468x60_as\"; google_ad_type = \"text_image\"; //2007-05-15: users_shop google_ad_channel = \"7041872983\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script></td> </tr> </table>$closeHTML"); } print "<table width=100% border=1 cellpadding=4 cellspacing=0 bordercolor=#CCCCCC bgcolor=#FFFFFF> <tr> <td><p><script type=\"text/javascript\"><!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 468; google_ad_height = 60; google_ad_format = \"468x60_as\"; google_ad_type = \"text_image\"; //2007-05-15: users_shop google_ad_channel = \"7041872983\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script><br><br><b>$find_shop[shop_name]</B> <font size=-1><i>size $find_shop[shop_size]</i></font></p><p>$find_shop[shop_desc]</p> <center><br><br><table width=100% cellpadding=10>"; $x = 0; $query = mysql_query("SELECT * FROM usershops_items2 WHERE owner = '$find_owner[id]' AND price > '0' AND game = '$game' ORDER BY item_id"); while ($array = mysql_fetch_array($query)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$array[item_id]' AND game = '$game'"); $y = $x % 5; if ($y == 0) { echo "<tr>"; } echo "<td><p align=center><a href='usershop.pro.php?game=$game&user=$user&id=$array[id]&price=$array[price]' onClick=\"if ( !confirm ('Are you sure you want to purchase this $get_item[item_name] for $array[price] $pointsVar?') ) { return false; }\"><img src=$base_url/images/user_images/opg_$game/items/item_$get_item[id].gif><br><font size=1><b>$get_item[item_name]</b><br>$array[stock] in Stock<br><i>$array[price] $pointsVar</i></A></p></td>"; if ($y == 4) { echo "</tr>"; } $x++; } print "</table></center><script type=\"text/javascript\"><!-- google_ad_client = \"pub-1131506519615518\"; google_ad_width = 468; google_ad_height = 60; google_ad_format = \"468x60_as\"; google_ad_type = \"text_image\"; //2007-05-15: users_shop google_ad_channel = \"7041872983\"; google_color_border = \"FFFFFF\"; google_color_bg = \"FFFFFF\"; google_color_link = \"F24475\"; google_color_text = \"000000\"; google_color_url = \"000000\"; //--> </script> <script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </script></td> </tr> </table>"; print "$closeHTML"; ?> Can anyone help? I've tried a couple of tutorials without any success.
  21. Thank you guys, your all absolute winners I really appreciate the help and now I have a base to work off for other pages. Thank you :-*
  22. Thank you for your help, although what I need is the table to display say 5 columns and rows added as needed. Currently I can have them all in one big row or all along side each other. eg: * = image * * * * * * * * * * * * * * *
  23. Hi, I need to have the output from the below code placed into a table and have no clue on how to do it. Any help is much appreciated. Using php and mysql <?php $rank_check = 0; include "header.inc.php"; $game=$_GET['game']; print "$openHTML"; ?> <b><font color="#FF3399" size="4" face="Arial, Helvetica, sans-serif">Trophy Case </font></b><br><br> <?php $sql_query = "SELECT * FROM `avatar` WHERE `owner` = $user_id ORDER BY `avatar`.`avatar_id` ASC"; //store the SQL query in the result variable $result = mysql_query($sql_query); if(mysql_num_rows($result)) { echo ("<table cellpadding=2 width=100%><tr>"); //output as long as there are still available fields while($row = mysql_fetch_row($result)) { echo ("<td><img src=$base_url/images/user_images/opg_1/trophy/$row[2].gif></td>"); } } //if no fields exist else { echo "This User has not won any trophies"; } echo ("</tr></table>"); print "$closeHTML"; ?>
×
×
  • 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.