这可能吗??如果是而不是代码有什么问题导致它不起作用,否则建议另一种有效的方法,因为如果我使用(if else)语句,它将变得混乱,大约 24 到 26 个 if else 条件......以及还有 4 个 case 语句
重写代码
代码:
<?php
$c = mysql_connect("localhost", "abc", "xyz");
mysql_select_db("root");
$bodytype = $_GET["name"]; //from another page through ajax
$company = $_GET["name2"]; //from another page through ajax
$Array = array($bodytype,$company );
$q="select * from product";
$qc=mysql_query($q);
$ans=mysql_fetch_array($qc);
$ans[6];
$ans[1];
switch ($Array)
{
case array($ans[6],$ans[1]):
$q="select * from product where bodytype='$bodytype'&& Companyname='$company' GROUP BY modelname";
$qc=mysql_query($q);
$ans=mysql_fetch_array($qc);
$count=0;
while($ans=mysql_fetch_array($qc))
{
if ($count == 0 || $count == 1 || $count == 2)
{
$title=ucwords($ans[1]." ".$ans[2]);
print "<div class='img-wrap'>
<img id='display_img' src='products/$ans[8]' width=300 height=200 title='$title'>
<div class='img-overlay'>
<input type='checkbox' id='compare_pro' /> Add to compare
<h4>".$title."</h4>
<p>".nl2br($ans[9])."</p>
<p>"."<b>Versions:</b> ".$ans[3]."</p>
<p>"."<b>Starting Price:</b>"." ₹ ".$ans[4]."</p>
</div>
</div>";
}
$count++;
if($count==3)
{
print "<br />";
$count = 0;
}
}
break;
case array($ans[6],'not'):
$q="select * from product where bodytype='$bodytype' GROUP BY modelname";
$qc=mysql_query($q);
$count=0;
while($ans=mysql_fetch_array($qc))
{
if ($count == 0 || $count == 1 || $count == 2)
{
$title=ucwords($ans[1]." ".$ans[2]);
print "<div class='img-wrap'>
<img id='display_img' src='products/$ans[8]' width=300 height=200 title='$title'>
<div class='img-overlay'>
<input type='checkbox' id='compare_pro' /> Add to compare
<h4>".$title."</h4>
<p>".nl2br($ans[9])."</p>
<p>"."<b>Versions:</b> ".$ans[3]."</p>
<p>"."<b>Starting Price:</b>"." ₹ ".$ans[4]."</p>
</div>
</div>";
}
$count++;
if($count==3)
{
print "<br />";
$count = 0;
}
}
break;
?>
switch 语句中是否可以有多个控制变量?
例子 :
a=1;
b=2;
switch(a , b)
{
case(1,2): print "true";
break;
case(2,1): print "false";
break;
}