Mysqli查询不返回结果

时间:2016-10-16 14:12:32

标签: php mysqli

你好我是mysqli的新手,我试图找出返回与loged用户id相邻的其他用户id的最佳方法。这是我目前的代码,不起作用。

<html>

<head>

<?php session_start(); ?>

<link rel="stylesheet" type="text/css" href="core/styles.css">

</head>

<body>

    <?php include 'core/modules/nav.php'; ?>



    </body>

    <?php
    //Connect to DB
    include "core/database/dbConnect.php";

    $id = $_SESSION['id'];

    $query = "SELECT user_one FROM conversation WHERE user_two = $id 
            UNION ALL
            SELECT user_two FROM conversation WHERE user_one = $id ";

    if(mysqli_query($conn, $query)){
        printf("Select returned %d rows.\n", mysqli_num_rows($result));

        mysqli_free_result($result);
    }else{
        echo $error;
    }

    mysqli_close($conn);


    ?>

数据库连接

<?php
$error = "Sorry, Somthing went wrong! Please contact a Administrator. Thank          You!";

$conn = NEW MySQLi('localhost', 'root', '', 'Indigo') or die($error);
?>

此声明不断返回:

if(mysqli_query($conn, $query))

我相信我这样做是正确的,但谁知道呢。我可能正在查询最困难的方式。谢谢。

0 个答案:

没有答案