Abdul Waheed Abdul Waheed - 1 month ago 7
HTML Question

How can i fetch multiple values with id and store in a variable

here is my code of eligible branches i am trying fetch multiple branches with one job id and store the array in a variable

$branches
and i want to send this in a mail body content as
$branches
for example it includes
cse,it,mech
for job id
38


i am selecting from
r_job_branch
for multiple branches

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


i am selecting from
r_branch
for multiple branch names

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


i want to use that variable in this:

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

Answer

Loop around putting out the branch name.

Using a JOINed query and making a guess at how your db connection is working:-

<?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>';