简体   繁体   中英

PHP return results from MySQL Query

I'm fairly new to PHP, but here is my issue, I am trying to get the results from a SQL query to display on the page, but I'm not getting anything returned.

Here is the code that I'm currently working with:

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

This is what I get returned:

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

Any help would be appriciated.

Do a var_dump($row) and see what is in the row variable.

That will help to see whether you have those data in those returning data set.

Based on the output, you are getting some data and returning data might not have the columns you are looking for.

Hope it helps.

Check your database first.

After set sql query, try this code:

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

echo $sql;

Copy and paste sql query into DB client like mysqladmin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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