$searchquery = mysql_query("SELECT * FROM regform_admin WHERE status = 'Approved' AND month LIKE '%".$checkmonth."%' AND day LIKE '%".$checkday."%' AND year LIKE '%".$checkyear."%' OR month2 LIKE '%".$checkmonth."%' AND day2 LIKE '%".$checkday."%' AND year2 LIKE '%".$checkyear."%' OR betday LIKE '%".$checkday."%'");
while($fetchres = mysql_fetch_array($searchquery)) {
$vehicles = $fetchres['vehicles'];
echo "<b>$vehicles</b><br>";
}
include "vehicledbconnect.php";
$searchquery2 = mysql_query("SELECT * FROM vehicletbl WHERE vehicle NOT LIKE '%".$vehicles."%'");
while($fetch = mysql_fetch_array($searchquery2)) {
$v = $fetch['vehicle'];
$vehed = $fetch['vehed']; $vehcap = $fetch['vehcap']; $vehyr = $fetch['vehyr'];
$type = $fetch['type'];
echo "<tr>";
echo "<td class=light><input type = 'checkbox' name='chk[]'></td>";
echo "<td class=light>$v</td>";
echo "<td class=light>$type</td>";
echo "<td class=light>$vehyr</td>";
echo "<td class=light>$vehed</td>";
echo "<td class=light>$vehcap</td>";
echo "<td class=light>$vehcolor</td>";
echo "</tr>";
echo "$array";
}
是否可以在$ searchquery2内的$ searchquery中回显while语句中的所有值?
例如$ searchquery的值是:
vehicle1
vehicle2
vehicle3
现在我要在$ searchquery2内回复所有内容,是否可能?我尝试在$ searchquery2中回显$ vehicles(来自$ searchquery),但它只回显最后一个值(例如.carve3),因为我知道它不在$ searchquery的while语句中。
有可能吗?感谢。
答案 0 :(得分:1)
在循环中构建循环。
试试这个:
mysql_query("SELECT * FROM regform_admin WHERE...")
while(...)
{
$vehicles = $fetchres['vehicles'];
echo "<b>$vehicles</b><br>";
mysql_query("SELECT * FROM vehicletbl WHERE vehicle NOT LIKE '%".$vehicles."%'");
while(...)
{
echo ...
}
}
答案 1 :(得分:0)
而不是echo
在while循环中,尝试将输出缓冲到变量:
$ob = '';
while($fetchres = mysql_fetch_array($searchquery))
$ob .= '<b>' . $fetchres['vehicles'] . '</b><br>';
echo($ob);
在第二次while循环期间,$ob
仍处于活动状态,您可以轻松地将其回显。在这里,我将其存储为字符串,但如果您需要对元素进行更细粒度的访问,也可以将值存储为数组。
<强>更新强>
如果您想将它们存储到数组中,请尝试这种方式:
$ob = array();
while($fetchres = mysql_fetch_array($searchquery))
$ob[] = $fetchres['vehicle']; // This pushes the current vehicle onto the end of the array
在这个循环之后,你只需要数组中每个车辆的字符串,而不是格式化。您可以在输出元素时添加它。使用foreach
:
foreach($ob as $k => $v) {
// Inside this loop, $k is the key, or index, and $v is the value.
// You can change the names of these variables by modifying the line above, e.g.
// foreach($ob as $foo => $bar) <-- $foo = key/index, $bar = value
}