duanbipu1720 2013-08-29 13:45
浏览 40
已采纳

PHP查询对字符串的响应

I'm running a PHP query which returns several rows / columns. (Im returning the columns: name, quantity, unit, producer, notes) * X rows (depending on how many rows were found in the database).

$sql = "SELECT products.name, products.unit, lists.quantity, lists.producer, lists.notes FROM lists,products WHERE lists.familyid ='$familyid' AND lists.productid = products.id ";
$sqlmessage=mysql_query($sql);

Now i would like to arrange this response into a STRING, in order to email it using mail($to,$subject,$message,$headers).

Im trying to use the following function, however im not getting the correct list but rather alot of " fetchColumn(name) "

The Broken function:

for ($i=0; $i<mysql_num_rows($sqlmessage); ++$i){
    while ($row = mysql_fetch_array($sqlmessage)){
        $name = $row->fetchColumn($i);
        $message .= "$name";
        $message .= ", ";
    }
}

What do i need to change to get the correct information out ? Been searching for a day now and trying different things without any success.'

  • 写回答

1条回答 默认 最新

  • dongmangji0950 2013-08-29 13:48
    关注

    You are using two loops (i dont know why) and object to mysql_fetch_array() .Do you mean something like this?:

    while($row = mysql_fetch_array($sqlmessage))
    {
        $name = $row['name'];
        $message .= $name;
        $message .= ", ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?