Jump to content

Need help with MySql queries


macky

Recommended Posts

First, the background, I'm doing an RPG, when you sign up, your class you chose is inserted along with your record, into the database, each class has a number.

What I need is code that would allow me to take that number, write it as a variable, then do a few if statements, to eventually lead up to the displaying of the class as an echo. 

What I don't know how to do, is get the results of a MySQL query to be stored as a variable ($class)

(none the less, how would I search a given table for their username / then find their class)

I'm very new at PHP coding, so the more explanation the better :-)

Thanks in advance, and sorry if its already been posted somewhere.
Link to comment
Share on other sites

Maybe something like:
[code]
//Url would be something like www.domain.com/index.php?username=USERNAMEHERE
$username = $_GET['username'];
$query = "SELECT class FROM table WHERE username = '$username';
$result = mysql_query($query) OR die(mysql_error());
$row = mysql_fetch_array($result); //www.php.net/mysql_fetch_array
$class = $row['class'];

if ($class) {
//blah blah
}
else {
  //etc etc
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.