Jump to content

dynamically load a mysql table into a php object?


theagemaway

Recommended Posts

hey i gots a question.

im not that great at PHP, but im workin at it. can anyone tell me if this is possible?

Im making a game out of PHP/HTML, and what I want to do is store all the users and all the variables associated with that user in a MySQL table. simple, easy. now the tricky part is this. I want to load any certain user out of mysql and make that user into an object, and preserve all the columns that represent all the variables of that user.

here's what I mean

sql table:[font=courier]
|----------|------|-------|
| username | pass | email |
|----------|------|-------|
|-theagema-|-way--|-bob@y-|
|----------|------|-------|
[/font]

I want to be able to do something like

$guy = new User($POST_['username']);
echo $guy->username . "<br />";
echo $guy->pass . "<br />";
echo $guy->email . "<br />";

results in
theagema
way
bob@y


this is what i have so far.
--- code ---
class user {

public $username;
public $userinfo;

function __construct($username) {
$this->username = $username;
$query = "SELECT * FROM users WHERE username='$this->username'";
$result = mysql_query($query);
$userinfo = mysql_fetch_array($result);
}
}

--- end code ---

i dont think i have that code correct. but anyways, can someone help me devise a way to do this dynamically, and effectively?

thanks :)
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.