[英]Getting data from a mySQL query
我在使用MySQL時遇到一個非常簡單的問題。 我只是不太了解語法。
碼:
$Rego_select = mysql_query(
"SELECT VechicleRegistration FROM trucks WHERE TruckID = '$truckID'" )
or die("Problem reading table: " . mysql_error());`
如果我嘗試直接回顯$ Rego_select,它將輸出Resource Locater#。 我想知道我可以使用什么功能從該列獲取數據。
我試圖使用mysql_result(); 但是它需要一個位置編號,這使生活變得困難,因為我要在while語句中動態執行此查詢,並且如果這是唯一的方法,則必須重新編寫整個循環結構。
干杯們。
您應該能夠使用mysql_result()
。 它要求的位置只是結果中的位置。 當執行這樣的查詢時,只有一個結果。 mysql_result($Rego_select,0)
應該產生結果。
$query = mysql_query($query);
while($row = mysql_result($query)) {
print_r($row);
}
但是,請不要在此引用我的信息,因為我使用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.