0

我不明白我在这里做错了什么。我在表中有大约 125 个产品,但我只从表中得到最后一个产品,所以它只显示一个项目...这是一个简单的计算器,用于为销售人员和客户提供他们需要多少盒子,快速估算一下要花多少钱。提前感谢您的帮助..

<?php

include('admincik/config.php');
include ('birlikte/ac.thumbs.php'); 

//Retrieves data from MySQL 

 $data = mysql_query("SELECT * FROM Calculator ORDER BY isim") or die(mysql_error()); 
 //Puts it into an array 
 while($info = mysql_fetch_array( $data )) 
 { 
$resim = $info['resim'];
$isim = $info[isim];
$boyut = $info[boyut];
$pcs = $info[adet];
$sqft = $info[sqft];
$price = $info[price];
}
/////////Formdan gelen yada Giden//////////////
$length =htmlspecialchars(stripslashes($_POST['Length'])); 
$width =htmlspecialchars(stripslashes($_POST['Width'])); 
$TileNameList = "<option value=\"$sqft\">$isim $boyut</option>";

/////Matematiksel islemler/////////

$equals = $length * $width;
$box = round($equals / $sqft);
$sqftbox = $box * $sqft;
$TotalPrice = $sqftbox * $price

?>
<div class="ana">
  <table width="900" height="199" border="1">
    <tr>
      <td width="150">Name</td>
      <td width="150">Length</td>
      <td width="150">Width</td>
      <td width="150">Total Sqft Area</td>
      <td width="200">Box Needed /Total Sqft</td>
      <td width="100">Price</td>
    </tr>
    <tr>
      <td><form id="form5" name="form5" method="post" action="">
        <select name="TileName" id="TileName">
<?php echo ($TileNameList); ?>
        </select>
      </td>
      <td><input name="Length" type="text" id="Length"/></td>
      <td><input type="text" name="Width" id="Width"/></td>
      <td><input type="text" name="Sqft" id="Sqft" value="<?php echo ($equals); ?>"/></td>
      <td><?php echo "You will need <span style=\"color:red\">$box</span> Boxes<br> Which is <span style=\"color:red\">$sqftbox</span> "; ?></td>
      <td><?php echo "$$TotalPrice"; ?></td>
    </tr>
    <tr >
      <td colspan="6" align="center">
        <input type="submit" name="Submit" id="Submit" value="Submit" />
      </form></td>

    </tr>
  </table>

</div>
4

1 回答 1

1

您的循环不会附加到 $TileNameList 因为它存在于它之外。它实际上取代了它的价值。尝试:

<?php

include('admincik/config.php');
include ('birlikte/ac.thumbs.php'); 

//Retrieves data from MySQL 

 $data = mysql_query("SELECT * FROM Calculator ORDER BY isim") or die(mysql_error()); 
 //Puts it into an array 
 while($info = mysql_fetch_array( $data )) 
 { 
$resim = $info['resim'];
$isim = $info[isim];
$boyut = $info[boyut];
$pcs = $info[adet];
$sqft = $info[sqft];
$price = $info[price];
$TileNameList .= "<option value=\"$sqft\">$isim $boyut</option>";   // NOTE THE .=
}
/////////Formdan gelen yada Giden//////////////
$length =htmlspecialchars(stripslashes($_POST['Length'])); 
$width =htmlspecialchars(stripslashes($_POST['Width'])); 


/////Matematiksel islemler/////////

$equals = $length * $width;
$box = round($equals / $sqft);
$sqftbox = $box * $sqft;
$TotalPrice = $sqftbox * $price

?>
<div class="ana">
  <table width="900" height="199" border="1">
    <tr>
      <td width="150">Name</td>
      <td width="150">Length</td>
      <td width="150">Width</td>
      <td width="150">Total Sqft Area</td>
      <td width="200">Box Needed /Total Sqft</td>
      <td width="100">Price</td>
    </tr>
    <tr>
      <td><form id="form5" name="form5" method="post" action="">
        <select name="TileName" id="TileName">
<?php echo ($TileNameList); ?>
        </select>
      </td>
      <td><input name="Length" type="text" id="Length"/></td>
      <td><input type="text" name="Width" id="Width"/></td>
      <td><input type="text" name="Sqft" id="Sqft" value="<?php echo ($equals); ?>"/></td>
      <td><?php echo "You will need <span style=\"color:red\">$box</span> Boxes<br> Which is <span style=\"color:red\">$sqftbox</span> "; ?></td>
      <td><?php echo "$$TotalPrice"; ?></td>
    </tr>
    <tr >
      <td colspan="6" align="center">
        <input type="submit" name="Submit" id="Submit" value="Submit" />
      </form></td>

    </tr>
  </table>

</div>
于 2013-02-08T03:01:39.283 回答