0

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 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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mate. Worked like a charm.
1
$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.

Comments

0
<?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 ;
                }   
                }    

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.