您好我有2个表,一个名称标签带有一堆名称,另一个名称带有2个colomns,一个是与表标签中的标记名匹配的标签,另一个是图像链接的img ...所以我在尝试要做的是用其他表格标签中的相应标签拉出所有图像...但我仍然没有想到如何设置哪些标签......至此我的尝试到目前为止...谢谢!
public function getallComplaints_reasign_test()
{
$myQuery = "select * from app_complaint where assigned_to != 'not assigned'";
$q1 = $this->db->query($myQuery);
if($q1->num_rows() > 0)
{
foreach (($q1->result()) as $row1)
{
$compid=$row1->com_id;
$engine=$row1->engine_model;
$tch = $row1->assigned_to;
$tch1=explode(',',$tch);
$tch2=array();
foreach($tch1 as $types)
{
$techname="select technician_name from technicians where id='$types'";
$q2 = $this->db->query($techname);
if($q2->num_rows() > 0)
{
$row2 = $q2->row();
$tch2[]= $row2->technician_name;
}
}
$tech=implode(',',$tch2);
$cmpl[]=array('com_id'=>$compid,'name'=>$cust,'com_type'=>$comptype,'engine_model'=>$engine,'assigned_to'=>$tech);
}
}
return $cmpl;
}
答案 0 :(得分:1)
使用mysql join在一个查询中获取它们:
$options=mysql_query("SELECT t.tagname tagname, i.img img FROM tags t join imgs i on i.tagname = t.tagname ORDER BY t.tagname ASC");
echo "<form action='' metod='GET'>";
$tags_displayed = array();
while($row=mysql_fetch_array($options)) {
$tag=$row['tagname'];
$img = $row['img'];
if(!isset($tags_displayed[$tag])){
echo "<input type='checkbox' value='".$tag."'>".$tag."</input>";
$tags_displayed[$tag]=1;//unique tag displayed only once
}
echo "<img src='arimg/".$img."' height='300' width='300'>";
}
echo "</form>";
请注意 - 不推荐使用mysql_函数,而是使用mysqli或PDO编写的语句。