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
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
Share on other sites

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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.