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! Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/ 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. Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-493956 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 Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-493963 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? Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-493965 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-493974 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!) Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494078 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. Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494132 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! Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494155 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? Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494169 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)... Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494213 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. Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494255 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) Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494259 Share on other sites More sharing options...
sbourdon Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks; everything's running perfectly now! Link to comment https://forums.phpfreaks.com/topic/96531-sql-query-help/#findComment-494947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.