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 .= ", ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?