using numbers for field value in table - mySQL

ENIAC

Member
Sep 4, 2001
69
0
0
I have 5 or 6 fields in my database that are 3 numbers long (ex. 333, 563, 234). I want to select the value in one of the fields where = $id_val. The trick is, is I get the field value from a variable. So far here is what I have and cannot get to work:

$get_val = mysql_query("select '$num_in_var' from chara where id='$id_val'");
$val = mysql_fetch_array($get_val);



Zack
 

kt

Diamond Member
Apr 1, 2000
6,032
1,348
136
I am not sure I completely understand what you are trying to do. You can't select a value, but you may select a row or a field (that contains a value). You mind explaining what exactly you are trying to do?

-Edit-

Ok, I just read your thread title and I think I know what you are trying to say..

Your field name is a number (you made it confusing by saying it's a field value). You almost got it..

when you set $val = mysql_fetch_array($get_val), it fetches the value and store it to $val as an array. So, the value you are trying to access is $val['$num_in_var'].
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
$result = mysql_query("select * from chara where id='$id_val'");
$myrow = mysql_fetch_array($result);
$value = myrow["columnName"];

that will do what you want, I think
how, I dont know what $num_in_var was supposed to be. If you odnt know which field to select yet, just use the above code and change the $value line to use the correct column
 

kt

Diamond Member
Apr 1, 2000
6,032
1,348
136
Originally posted by: CTho9305
$result = mysql_query("select * from chara where id='$id_val'");
$myrow = mysql_fetch_array($result);
$value = myrow["columnName"];

that will do what you want, I think
how, I dont know what $num_in_var was supposed to be. If you odnt know which field to select yet, just use the above code and change the $value line to use the correct column

I think he meant $num_in_var to be the fieldname passed in from a variable. I believe he's using 3-digit numbers for his fieldnames.

 

ENIAC

Member
Sep 4, 2001
69
0
0
Originally posted by: kt
Originally posted by: CTho9305
$result = mysql_query("select * from chara where id='$id_val'");
$myrow = mysql_fetch_array($result);
$value = myrow["columnName"];

that will do what you want, I think
how, I dont know what $num_in_var was supposed to be. If you odnt know which field to select yet, just use the above code and change the $value line to use the correct column

I think he meant $num_in_var to be the fieldname passed in from a variable. I believe he's using 3-digit numbers for his fieldnames.

This looks right but instead of "select * from chara where id='$id_val'" I want the * to be a row in the table whose name comsists of 3 numbers. (i.e. I just want it to get that one row instead of the whole thing)

 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Oh I see.
what you had originally was almots right:

$get_val = mysql_query("select $num_in_var from chara where id='$id_val'");
$val = mysql_fetch_array($get_val);

column names NEVER go in quotes ;) (remove the quotes around $num_in_var)