Reputation: 12113
$query = "SELECT val FROM table WHERE id = 1";
mysql_query($query);
This returns a single peice of data from the database. all the ways I know how to deal with this data are mysql_fetch_array() and mysql_fetch_assoc() is there a way to deal with 1 peice of data that doesn't involve pulling it into an array?
Upvotes: 0
Views: 87
You can use mysql_result()
like this;
mysql_result(mysql_query($query), 0, 0);
The second parameter selects the row, and the third is the field number.
Upvotes: 1
Reputation: 943108
There is mysql_fetch_field
which appears to do what you want.
mysql_fetch_field(0,0);
Upvotes: 1
Reputation: 300825
Many wrapper libraries offer this, for example, with ADODb, it's simple
$value=$db->GetOne("select val from table where id=1");
It's not hard to roll your own either.
Upvotes: 1