PHP从语句中选择

时间:2017-04-04 11:14:22

标签: php

我正在尝试做这样的php select语句:

  $select = mysql_query("select * from message where receiver_id = '$receiver_id'and frm_id = '$frm_id' ORDER BY id DESC");
    while($row = mysql_fetch_array($select))
    {
        $id = urlencode(encryptor('encrypt', $result['user_id']));
        $query = mysql_query($sql);
        $result = mysql_fetch_assoc($query);
    }

但它的工作只是select from table where frm_id = $frm_id而已。

3 个答案:

答案 0 :(得分:0)

使用PDO可以执行以下操作:

$id = "Id wanted here";
$conn = new PDO("server", "username", "password");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $conn->prepare("SELECT * from `tablename` WHERE `receiver_id` = :id");
$sth->bindParam(':name', $id);
$sth->execute();

答案 1 :(得分:0)

我认为有两个错误。

1:您在定义$ result之前使用$ result [' user_id']。 2:$ sql没有定义。 我也不确定加密方法。

答案 2 :(得分:0)

您可以尝试:

 $select= mysql_query("select * from message where receiver_id = $receiver_id  
 and frm_id = $frm_id ORDER BY id DESC");

$select= mysql_query("select * from message where receiver_id = $receiver_id  
or frm_id = $frm_id ORDER BY id DESC");