Getting data from a mySQL query
I'm having a fairly simple issue with MySQL. I just don't know the syntax well.
CODE:
$Rego_select = mysql_query(
"SELECT VechicleRegistration FROM trucks WHERE TruckID = '$truckID'" )
or die("Problem reading table: " . mysql_error());`
If i try to echo $Rego_select directly it outputs Resource Locater #. I am wondering开发者_StackOverflow what function I can use to get the data from that column.
I tried to use mysql_result(); but it requires a position number which makes life difficult because I am executing this query dynamically in a while statement and I would have to re write the whole loop structure if this is the only way to do it.
Cheers guys.
You should be able to use mysql_result()
. The position it requires is just the position in the result. When executing a query like that, there's only one result. mysql_result($Rego_select,0)
should yield the result.
$query = mysql_query($query);
while($row = mysql_result($query)) {
print_r($row);
}
But don't quote me on that, I've been using ADODB for so long now I can't remember the mysql_etc syntax.
<?php
$Rego_select = mysql_query(
"SELECT VechicleRegistration FROM trucks WHERE TruckID = '$truckID'" ) ;
if($Rego_select)
{
while($row=mysql_fetch_object($Rego_select))
{
if( $row->VechicleRegistration )
echo $valid= $row->VechicleRegistration ;
}
}
?>
精彩评论