2017-09-26 182 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。