Jump to content

Archived

This topic is now archived and is closed to further replies.

theagemaway

dynamically load a mysql table into a php object?

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

Share this post


Link to post
Share on other sites

×

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.