Mysql显示所有记录

时间:2014-09-17 10:09:56

标签: php mysql

我需要一个SQL查询,如果它也是重复的,则显示所有记录。比如说

select * from table where true and p_id in(1,2,1,1)

仅显示1和2中的记录,但我需要在while循环中给出重复记录。

使用代码进行更新:

$cook = unserialize($_COOKIE["pro_cook"]);
foreach ($cook as $something) {
  $merc[] = $something;
}
foreach ($size as $new_size) {
  $size_array[] = $new_size;
}

$items = count($merc);
$mer = rtrim(implode(',', array_reverse($merc)), ',');
$fulclr = "and p_id in (".$mer.")";
$asd = "(p_id,".$mer.")";
$result = mysql_query("select * from product_details where true ".$fulclr." order by field".$asd."");

1 个答案:

答案 0 :(得分:1)

希望这会有所帮助

$ids = "1,2,1,1";

$sql = "select * from table where true and p_id in (".$ids.")";
$rec = mysql_query($sql);

$dbData = array();
while($res = mysql_fetch_assoc($rec)) {
    $dbData[$res['p_id']] = $res;
}

$ids = explode(',', $ids);

$newArray = array();
foreach ($ids as $id) {
   if (!empty($dbData[$id])) {
       $newArray[] = $dbData[$id];
   }
}