Deanznet Posted November 26, 2007 Share Posted November 26, 2007 Hey Their Im working on this game but im having trouble. I can select information from a 1 specific user but i really cant figure out how to select it using the session. <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { $database="N/A"; mysql_connect ("N/A", "N/A", "N/A"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; echo('Hi' . $userdata['username'] . '!'); } else { echo('You are a guest'); } ?> See here I thought it would be something like this $result = mysql_query( "select username,user_points from phpbb_users where $userdata['username']'" ) But that dosent work either.. Any help would be great. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 26, 2007 Share Posted November 26, 2007 If you are building within the phpBB environment, you should not have to do all of this work... You have missed some included files which will allow you to use their MySQL abstraction layer. You won't have to 'connect' and all that stuff, and you'll have the object $db to make SQL queries with. Is this a phpBB2 installation? If so, I can provide you with the right start-up includes to access their kung-foo. PhREEEk Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 27, 2007 Author Share Posted November 27, 2007 Im using trying to make a phpbb game kinda.. Well its going to be all based on phpbb.. I have phpbb board with the arcade and cash mod.. So for people to make games they either post or play the arcade. Then they get money they can spend in the game. I dont know how to display the cash they have in the database thats what is what i was trying to do Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 I have to run a few errands, but I'll be back in a bit with some examples and test data to run. Once you see how easy it all is, you'll laugh... PhREEEk Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 27, 2007 Author Share Posted November 27, 2007 Alright Thanks Man Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 Ok, I have 2 things to try with your script. Run them separately, and post the results separately. Test one: <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... echo "<pre>"; print_r($userdata); die("</pre>"); if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { $database="N/A"; mysql_connect ("N/A", "N/A", "N/A"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; echo('Hi' . $userdata['username'] . '!'); } else { echo('You are a guest'); } ?> Test two: <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... $sql = "SELECT * FROM `phpbb_users`"; if ( !result= $db->sql_query($sql) ) { die('MySQL Error'); } $num_rows = $db->sql_numrows($result); echo "$num_rows Users found!"; die(); if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if($userdata['session_logged_in']) { $database="N/A"; mysql_connect ("N/A", "N/A", "N/A"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; echo('Hi' . $userdata['username'] . '!'); } else { echo('You are a guest'); } ?> PhREEEk Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 27, 2007 Author Share Posted November 27, 2007 First one shows Array ( [user_id] => 3 [user_active] => 1 [username] => Myusername [user_password] => md5hash [user_session_time] => 1193232535 [user_session_page] => 0 [user_lastvisit] => 1196121530 [user_regdate] => 1152063005 [user_level] => 1 [user_posts] => 237 [user_timezone] => -4.00 [user_style] => 5 [user_lang] => english [user_dateformat] => D M d, Y g:i a [user_new_privmsg] => 0 [user_unread_privmsg] => 0 [user_last_privmsg] => 1195881794 [user_login_tries] => 0 [user_last_login_try] => 0 [user_emailtime] => [user_viewemail] => 0 [user_attachsig] => 1 [user_allowhtml] => 0 [user_allowbbcode] => 1 [user_allowsmile] => 1 [user_allowavatar] => 1 [user_allow_pm] => 1 [user_allow_viewonline] => 1 [user_notify] => 0 [user_notify_pm] => 1 [user_popup_pm] => 1 [user_rank] => 1 [user_avatar] => Comics/008.jpg [user_avatar_type] => 3 [user_email] => dino_x9@hotmail.com [user_icq] => [user_website] => [user_from] => 435 south.. wait why am i telling you this? [user_sig] => [user_sig_bbcode_uid] => [user_aim] => Soul+Reaper89 [user_yim] => [user_msnm] => dino_x9@hotmail.com [user_occ] => [user_interests] => [user_actkey] => [user_newpasswd] => [user_birthday] => 999999 [user_next_birthday_greeting] => 0 [user_allowdesc] => 0 [user_allowmoddesc] => 0 [user_showdescriptions] => 0 [user_showtooltips] => 0 [user_tooltips_parse] => 1 [user_tooltips_static] => 0 [user_toolimg_width] => 1 [user_toolimg_height] => 1 [user_show_quickreply] => 1 [user_quickreply_mode] => 1 [user_open_quickreply] => 1 [games_block_pm] => 1 [user_troll] => 0 [user_adr_ban] => 0 [user_cell_time] => 0 [user_cell_time_judgement] => 0 [user_cell_caution] => 0 [user_cell_sentence] => [user_cell_enable_caution] => 0 [user_cell_enable_free] => 0 [user_cell_celleds] => 0 [user_cell_punishment] => 0 [user_points] => 45093 [arcade_banned] => 0 [session_id] => be3214321312c4526af27ea12312406 [session_user_id] => 3 [session_start] => 119122318 [session_time] => 1196132535 [session_ip] => 4514322cd [session_page] => 0 [session_logged_in] => 1 [session_admin] => 0 ) Test 2 Showed My Users you dont need the Db Connection information works without it. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 27, 2007 Share Posted November 27, 2007 Ok, looks like you're all setup... >I dont know how to display the cash they have in the database thats what is what i was trying to do If that's user_points, then phpBB has already populated that into $userdata. If you refer to the print_r dump, you'll see every user stat that is available to you at any point, on any page. You don't need to use a separate session. so: <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); // // Start session management // $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); // // End session management // // Sorry , only logged users ... if ( !$userdata['session_logged_in'] ) { $redirect = "traded.$phpEx"; $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if( $userdata['session_logged_in'] ) { echo "<table width=\"200\" border=\"1\"> <tr> <td><font face=arial size=\"1\">$userdata['user_points']</font></td> </tr> </table> <p> Hi $userdata['username']!</p>"; } ?> Should get the job done... PhREEEk Quote Link to comment Share on other sites More sharing options...
Deanznet Posted November 27, 2007 Author Share Posted November 27, 2007 Thanks alot man Really Helped Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.