Jump to content


Card Quest Script

  • Please log in to reply
4 replies to this topic

#1 dottore11

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 May 2006 - 01:26 AM

Ok, so I am starting this new game on my website, and it will be called Card Quest or something similar to that. Basically, they need to complete different objectives to earn cards to add to their online "collections". What I need is a script that will allow me to:

1. Manage and add new users to the system, and later add cards they have earned
2. Allows a way to display the users and which cards they have collected and which ones they haven't.

Here's the idea;

I'm a visitor and I want to view which cards "Susie" has collected. So I click her name in the userlist and up pops a window that has highlighted which cards they have collected out of the total number of cards. Clicking the name of the card or rolling over it shows the picture of the card.


Right now I'm in the phase of the project where I am developing the admin panel that will let me add and edit the users/cards. I have completed the part that adds users and their respective cards to the database, but now I'm on the editing part.

I've figured out a primitive update script that will work for me: here's what I have;
@mysql_select_db($database) or die( "Unable to select database");
<form action="updated.php" method="post">
Username: <input type="text" name="ud_usernamec"><br>
Air: <input type="checkbox" name="ud_air"><br>
Dark: <input type="checkbox" name="ud_dark"><br>
<input type="Submit" value="Update">


$query="UPDATE cardbase SET air='$ud_air', dark='$ud_dark' WHERE usernamec='$ud_usernamec'";
@mysql_select_db($database) or die( "Unable to select database");
echo "Record Updated";
My problem is that for example, if a user already has a card, I have to click the checkbox for that card anyways, or it will get submitted and turn the value for that row on that user to off. Does that make sense? I know now that it shouldn't be hard since there are only 2 cards, but once I get this going there are like 42 total.

So, you can see me having to click the checkboxes over and over could get old. Is there anyways I can modify the update.php script or something else where if the checkbox is submitted without a value that it isn't put in as a 0?

#2 JasonLewis

  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 15 May 2006 - 02:28 AM

first of all i would make it so they must enter the username and search for the user first.

then on the next page retrieve the variables for the database.
so get like the variable Air and the variable Dark from the database. Then you can just use some simple if commands like so:

if($dark == "1"){
<input type="checkbox" name="ud_dark" value="$dark" selected>
<?php }else{ ?>
<input type="checkbox" name="ud_dark" value="$dark">
<?php } ?>

that should work pretty good i think. lol. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

its just that you would have to do that for every checkbox. and there is probably an easier way but that way i showed works. good luck with your game.

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 dottore11

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 May 2006 - 02:40 AM

[!--quoteo(post=373883:date=May 14 2006, 10:28 PM:name=ProjectFear)--][div class=\'quotetop\']QUOTE(ProjectFear @ May 14 2006, 10:28 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
first of all i would make it so they must enter the username and search for the user first.

Ok, so how would I do that? Sorry to be so pesky -_- PHP is definitely not my specialty X_X

#4 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 May 2006 - 08:39 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]UPDATE cardbase SET air='$ud_air', dark='$ud_dark' WHERE usernamec='$ud_usernamec'[/quote]

It looks as though this table will eventually have 42 columns for the cards. A better design is

user               cardfile            card
===========        =============       =============
userID    <--+      recID        +---> cardID
username     |      cardID   ----+     cardname
etc          +----  userID

user data
 1  |   Peter
 2  |   Paul
 3  |   Mary
card data
 1  |   air
 2  |   dark
 3  |   water
 4  |   light
So if Peter has (air, dark) Paul has (air) Mary has (dark, water)
cardfile data
 recID | cardID  | userID
   1   |   1     |   1
   2   |   1     |   2
   3   |   2     |   3
   4   |   3     |   3
   5   |   2     |   1

This will enable you to process the query results and set the checkboxes in a simple loop instead of individually encoding each of the 42 possible cards for each user
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 dottore11

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 May 2006 - 01:24 AM

Ok, I've started to work on the script that the post before the previous one described. I don't want to totally redesign my script right now, plus I'm not quite understanding what I'd have to do to make that way work. Here's what I have:

Getuser.php - Asks user for the user they wish to edit and submits it to the next page
<form action="finduser.php" method="post">
Username: <input type="text" name="find_usernamec"><br>
<input type="submit"><br>

Finduser.php - Uses data from getuser.php and displays customized data in checkboxes based on whether their values in the table are on or not.

mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM cardbase WHERE usernamec='$find_usernamec'";
if($dark == "on"){
<input type="checkbox" name="ud_dark" checked="checked">
<?php }else{ ?>
<input type="checkbox" name="ud_dark">
<?php } ?>

Please note I've only done the script for Dark so far. The script is displaying an unchecked checkbox in places where it should be displaying a checked one. I have echoed some variables and the username is getting passed to the finduser.php page. Help please?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users