sbourdon Posted March 17, 2008 Share Posted March 17, 2008 Hello, I'm new at this and I'm trying to insert the default_league value in the users' table when a new account is being created. I've added this code to get its value from the DB, but it doesn't work: $sql = "SELECT config_value FROM " . FSPORTS_TABLE . " WHERE config_name = default_league"; if (!$result = $db->sql_query($sql)) { message_die(GENERAL_ERROR,'Error getting fsports defaults','',__LINE__,__FILE__,$sql); } $default_league = $row['default_league']; Do you see what's wrong in there? I'm totally lost... ??? Thanks a lot for your help and support! Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 $row isn't defined anywhere for starters. What does sql_query() return? Its not a standard php object. Quote Link to comment Share on other sites More sharing options...
sbourdon Posted March 17, 2008 Author Share Posted March 17, 2008 Thanks for your reply. Since I'm totally new at this, I've been trying to create a functionnal query by looking at existing lines in php files, but I didn't succeed... Could you simply tell me how I could get the value in the config_value column that is corresponding to the default_league in the config_name column? Not sure if this is clear... Let me know if it ain't; I'll included a screenshot from phpmyadmin! Regards, sbourdon Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 I could show you using the standard mysql extension but you seem to be using some sort of db wrapper object. Again I'll ask, What does sql_query() return? If your not sure, where did you get that object from? Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 A simple example using the standard mysql extension. <?php $sql = "SELECT config_value FROM " . FSPORTS_TABLE . " WHERE config_name = 'default_league'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $default_league = mysql_fetch_field($result,0); echo "The deafult league value is $default_league\n"; } } ?> Quote Link to comment Share on other sites More sharing options...
sbourdon Posted March 17, 2008 Author Share Posted March 17, 2008 Many thanks for these explanations! To make things clearer, here's a screenshot of the phpbb_fsports_config table in phpmyadmin: I need to get the value that's next to "default_league" (which is "9"). What should the SQL query look like? P.S.: I couldn't tell you what sql_query() should return; I got that code from one of phpBB's file (it's a trial and error process, but I'm learning!) Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 The code I posted will get the value your after. Quote Link to comment Share on other sites More sharing options...
sbourdon Posted March 17, 2008 Author Share Posted March 17, 2008 Unfortunately, it returns: The deafult league value is Object Any ideas? ??? Thanks for your patience! Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 Unfortunately, it returns: The deafult league value is Object Any ideas? ??? Thanks for your patience! The code I posted? Quote Link to comment Share on other sites More sharing options...
sbourdon Posted March 17, 2008 Author Share Posted March 17, 2008 Yes, the code you posted (straight copy / paste in a php file)... Quote Link to comment Share on other sites More sharing options...
tapos Posted March 17, 2008 Share Posted March 17, 2008 Try this <?php $sql = "SELECT config_value FROM " . FSPORTS_TABLE . " WHERE config_name = 'default_league'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $default_league = mysql_fetch_field($result,0); echo "The deafult league value is ".$default_league->config_value."\n"; } } ?> mysql_fetch_field always return object. that's why when you try to echo object it just print object. Hope this will clear you. Also please have a look at http://www.php.net/manual/en/function.mysql-fetch-field.php for more explanation about mysql_fetch_field. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 17, 2008 Share Posted March 17, 2008 use $default_league->def (mysql_fetch_field() returns an object) Quote Link to comment Share on other sites More sharing options...
sbourdon Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks; everything's running perfectly now! 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.