vegnadragon Posted January 19, 2008 Share Posted January 19, 2008 I am using phpbb but this is a regular php probelm, and i am new to object oriented, but the even thou i assing $data the value of the sql query, it doesn't contain any value on it. Any help? class status { var $data = array(); //This function will display all status function status() { global $db, $auth, $user, $template, $game; global $phpbb_root_path, $phpEx, $config; $user_id = $user->data['user_id']; $query = "SELECT * FROM status WHERE id_ref = ($user_id) LIMIT 1;"; $result = $db->sql_query($query); $this->data = $db->sql_fetchrow($result); $db->sql_freeresult($result); } Link to comment https://forums.phpfreaks.com/topic/86821-class-help/ Share on other sites More sharing options...
Northern Flame Posted January 19, 2008 Share Posted January 19, 2008 what do you want to put in $data? Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443734 Share on other sites More sharing options...
vegnadragon Posted January 19, 2008 Author Share Posted January 19, 2008 My query basically gets all values from my table. I want to add all those values to $data so that i can easily access it so i don't have to use sql all the time. So for example i can a $status = new status(); then i can use status->data['stuff']; Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443750 Share on other sites More sharing options...
vegnadragon Posted January 20, 2008 Author Share Posted January 20, 2008 i still can't asign value to data Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443897 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 I'm not sure what sql_fetchrow() is doing but if it just calls mysql_fetch_row then your $data variable will be an enumerated array, not a associative one. Also, I'm not sure if this: "SELECT * FROM status WHERE id_ref = ($user_id) LIMIT 1;" is valid SQL syntax. Can someone clarify? Either way, try this: "SELECT * FROM `status` WHERE `id_ref` = '$user_id' LIMIT 1;" Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443899 Share on other sites More sharing options...
vegnadragon Posted January 20, 2008 Author Share Posted January 20, 2008 I'm not sure what sql_fetchrow() is doing but if it just calls mysql_fetch_row then your $data variable will be an enumerated array, not a associative one. Also, I'm not sure if this: "SELECT * FROM status WHERE id_ref = ($user_id) LIMIT 1;" is valid SQL syntax. Can someone clarify? Either way, try this: "SELECT * FROM `status` WHERE `id_ref` = '$user_id' LIMIT 1;" I am using phpbb. sql_fetchrow is function that emulates mysql_fetchrow but with stuff, it all works, if i change $this->data for any variable i get my wanted array. i just can't asign it to my array. I want to assign the value on the array outside my function. Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443903 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 I'm confused. If you can replace $this -> data for any other variable and get your wanted array then I would suggest replacing $this -> data with any other variable and using that... Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443907 Share on other sites More sharing options...
vegnadragon Posted January 20, 2008 Author Share Posted January 20, 2008 I want to access it outside the functions so i can easy use for example $status->data[ex], instead of making 15 functions to do the same thing. Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443942 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Yes, I got that but you said it would work for any variable that wasn't $this -> data, so why not use $this -> icanhazcheezburger instead? Link to comment https://forums.phpfreaks.com/topic/86821-class-help/#findComment-443949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.