【问题标题】:How can i fetch multiple values with id and store in a variable如何使用 id 获取多个值并存储在变量中
【发布时间】:2017-03-15 15:12:09
【问题描述】:

这是我的合格分支代码,我正在尝试使用一个作业 ID 获取多个分支,并将数组存储在变量 $branches 中,我想在邮件正文内容中将其发送为 $branches,例如它包括 @ 987654323@ 工作 ID 38

我从r_job_branch 中选择多个分支

$branchquery=$conn->query("SELECT * FROM r_job_branch where id_job=".$jobId) or die(mysqli_error());
$branchres=$branchquery->fetch_assoc();
$eligiblebranches=$branchres['id_branch'];

我从r_branch 中选择多个分支名称

$bname=$conn->query("SELECT * FROM r_branch where id_branch=".$eligiblebranches) or die(mysqli_error());
$bres=$bname->fetch_assoc();
$branches=$bres['branch_name'];

我想在此使用该变量:

$message='<html><body><strong>Eligible Branches:</strong>'.$branches.'</body></html>';

【问题讨论】:

  • 您应该尝试循环并存储数据。

标签: php html mysql arrays mysqli


【解决方案1】:

循环输出分支名称。

使用 JOINed 查询并猜测您的数据库连接是如何工作的:-

<?php

$message = '<html><body><strong>Eligible Branches:</strong>';

$branchquery=$conn->query("SELECT a.id_branch,
                                b.branch_name
                            FROM r_job_branch a
                            INNER JOIN r_branch b
                            ON a.id_branch = b.id_branch
                            where id_job=".$jobId) or die(mysqli_error());

while($bres=$bname->fetch_assoc())
{
    $message .= $bres['branch_name']."<br />";
}
$message .= '</body></html>';

【讨论】:

    猜你喜欢
    • 2013-06-02
    • 2016-10-19
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多