class User {
var $dbRecords = array();//array that will hold db recordsfunction User() {
...constructor
}//}//end class
$sql = "SELECT * FROM user WHERE username = '".$_COOKIE["username"]."' LIMIT 1";
$user_res = mysql_query($sql) or die("Query failed : " . mysql_error());$user = new User();//call User class
while ($user_row = mysql_fetch_row($user_res)) {
$user->dbRecords[] = array(
'Username' => $user_row["username"],
'Password' => $user_row["password"],
'Agent Id' => $user_row["agent_id"],
'Reference' => $user_row["reference"],
'Level' => $user_row["level"],
'Email Address' => $user_row["email_address"],
'Email Username' => $user_row["email_username"],
'Email Password' => $user_row["email_password"]
);//end array
}//end whileTo access the information you just stored in your array:
foreach ($user->dbRecords as $records): print $records['Username']."<br>"; print $records['Password']."<br>"; print $records['Agent Id']."<br>"; print $records['Reference']."<br>"; print $records['Level']."<br>"; print $records['Email Address']."<br>"; print $records['Email Username']."<br>"; print $records['Email Password']."<br>"; endforeach;
If you want to a complete example that I have done
then go to http://www.randomthoughtprocess.com/AdminArticle.phps for the class and http://www.randomthoughtprocess.com/admin_article.phps for the
display. You don't have to use an array to store your db values. I do that so I can keep my class and display logic seperate.
Nunners wrote:
Hi all,
In the ongoing saga of moving the application I've developed from Apache to IIS, I've found another problem, with objects this time.
I've got a standard file that is included as a header, which includes the following lines:
[script]
$query = "SELECT * FROM user where username='".$_COOKIE["username"]."' LIMIT
1"; $user_res=mysql_query($query) or die("Query failed : " . mysql_error()); while ($user_row=mysql_fetch_row($user_res)) {
$user->username=$user_row["username"];
$user->password=$user_row["password"];
$user->agent_id=$user_row["agent_id"];
$user->reference=$user_row["reference"];
$user->level=$user_row["level"];
$user->email_address=$user_row["email_address"];
$user->email_username=$user_row["email_username"];
$user->email_password=$user_row["email_password"];
}
[/script]
When I then try and recall the object variable $user->username it comes up with an error: Notice: Undefined variable: user in C:\www\portal\global\var_setup.php on line 15
Notice: Trying to get property of non-object in C:\www\portal\global\var_setup.php on line 15
What do I need to do to declare the object before I write sections to it?
Cheers Nunners
-- Cory Wiles Systems Engineer ePerformax - Memphis, TN 901.751.4902 http://www.eperformax.com
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
