2017-09-26 177 views
1

我對PHP相當陌生,但這裏是我的問題,我試圖從SQL查詢中獲取結果以顯示在頁面上,但我沒有收到任何返回的結果。PHP返回MySQL查詢結果

這裏是我目前正在使用的代碼:

<?php 

$con = mysqli_connect("localhost","user","password","database"); 
if (mysqli_connect_errno()) { 
    echo "Connect failed: ". mysqli_connect_error(); 
} 

$de= $con->real_escape_string($_GET["decode"]); 

$sql = "select * from FG99_URL where short='".$de."'"; 
$result = mysqli_query($con, $sql); 

while($row = mysqli_fetch_assoc($result)) { 
     echo "url: " . $row["url"]. " - fb_url: " . $row["fb_url"]."<br>"; 

$url=$row['url']; 
$fb_url=$row['fb_url']; 
$fb_type=$row['fb_type']; 
$fb_title=$row['fb_title']; 
$fb_description=$row['fb_description']; 
$fb_image=$row['fb_image']; 
$petpro=$row['petpro']; 

echo $fb_url.'test 1</br>'; 
echo $row['fb_url'] . "test 2</br>"; 

print $fb_url."test 3</br>"; 
print $row['fb_url']."test 4</br>"; 

    } 
?> 

<head>... 

這是獲得返回什麼我:

url: - fb_url: 
test 1 
test 2 
test 3 
test 4 

任何幫助將appriciated。

+0

逐行調試 –

回答

1

執行var_dump($row)並查看行變量中的內容。

這將有助於查看這些返回的數據集中是否包含這些數據。

根據輸出結果,您將獲得一些數據,並且返回的數據可能沒有您正在查找的列。

希望它有幫助。

+0

感謝您的回覆。原來,我所有的列都是大寫的(url - > URL,fb_url - > FB_URL等) – Chris

0

首先檢查您的數據庫。

組SQL查詢後,試試這個代碼:

$sql = "select * from FG99_URL where short='".$de."'"; 

echo $sql; 

複製和SQL查詢粘貼到DB客戶像中mysqladmin。