Jump to content


dynamically load a mysql table into a php object?

  • Please log in to reply
No replies to this topic

#1 theagemaway

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 24 September 2006 - 04:28 AM

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:
| username | pass | email |

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

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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users