1

I have a database with 2 columns, one of type int and other of type varchar.

When i try to get tha name with id=1 for example, the query works fine:

$name = mysql_query("SELECT Name FROM stations_id WHERE id=1");
$a = mysql_fetch_array($name);
echo $a['Name'];

I try to do the opposite but i cant get the integer value. For example:

$id = mysql_query("SELECT id FROM stations_id WHERE Name='Mike'");
$a = mysql_fetch_array($id);
echo $a['id'];

I want to get the type as an integer so i can use it in a function. Can somebody help me plz?

4

2 回答 2

1

也许您的表中没有“迈克”作为名字

尝试:

$id = mysql_query("SELECT id FROM stations_id WHERE Name like '%Mike%'");
于 2013-03-17T14:57:17.897 回答
1

如果您绝对需要整数,则必须$a['id']自己转换为整数。然而,这很少是必要的。如果您$a['id']在整数上下文中使用(例如在算术运算中),它将自动转换为整数。

于 2013-03-17T14:44:00.747 回答