Jump to content


Photo

Little help with MySQL...


  • Please log in to reply
3 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 01 August 2006 - 07:13 AM

Hello,

I'm in need of knowing how to get data from one field, and from another, and so that they are associated.  For example...

CREATE TABLE config (
  config_name varchar(255) NOT NULL,
  config_value varchar(255) NOT NULL,
  PRIMARY KEY (config_name)

);

INSERT INTO config (config_name, config_value) VALUES ('max_file_size', '10000');

I'd want to get config_name's row max_file_size, and then have it draw the value 10000 out associated with it. This is what I have so far...

                  SELECT config_name,
                              config_value
                  FROM config
                  WHERE config_name = "max_file_size"
                  ORDER BY config_name

Will it work because it is primary key? Or do I have to do something else?

#2 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 01 August 2006 - 07:57 PM

Well, so yes, it appears this would be fine after doing a bit more research (config_name and config_value...values, were submitted into the same row. So I'd guess it draws the value of that row (max_file_size, as well).

Now, if this syntax isn't correct, please do, find my problem in it.

Anyway, I need to put the information into this:

$hidden_field = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $maxfilesize . "\" />";

So yes, $maxfilesize is probably not putting what I want, as I want the config_value put into value, and not config_name. But I want the config_name to get me the value of the row, and then put it in $maxfilesize.

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 01 August 2006 - 10:23 PM

SELECT config_name,
                              config_value
                  FROM config
                  WHERE config_name = "max_file_size"
                  ORDER BY config_name

You don't have to pull the config_name out of the database since you already know it. So, "SELECT config_value FROM config WHERE config_name='max_file_size'" will get the data you want, if I understand what it is you're trying to do.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 01 August 2006 - 10:51 PM

Ah, thanks, that will get what I want from the database.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users