Jump to content

SQL query help


sbourdon

Recommended Posts

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

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

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

Many thanks for these explanations!

 

To make things clearer, here's a screenshot of the phpbb_fsports_config table in phpmyadmin:

clipboard01ag5.th.jpg

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.