简体   繁体   English

从MySQL查询中获取数据

[英]Getting data from a mySQL query

I'm having a fairly simple issue with MySQL. 我在使用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 #. 如果我尝试直接回显$ Rego_select,它将输出Resource Locater#。 I am wondering what function I can use to get the data from that column. 我想知道我可以使用什么功能从该列获取数据。

I tried to use mysql_result(); 我试图使用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. 但是它需要一个位置编号,这使生活变得困难,因为我要在while语句中动态执行此查询,并且如果这是唯一的方法,则必须重新编写整个循环结构。

Cheers guys. 干杯们。

You should be able to use mysql_result() . 您应该能够使用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. mysql_result($Rego_select,0)应该产生结果。

$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. 但是,请不要在此引用我的信息,因为我使用ADODB已有很长时间了,所以我不记得mysql_etc语法了。

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

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM