Coderwannabe
Coderwannabe

Reputation: 407

Form Select List to show Product Names from Mysql Database

I dont get what im doing wrong here.. i have about 125 product in the table but i get only the last product from the table so it shows only one item... this is a simple calculator to provide the sales person and the customer how much box they would need and how much it would cost a quick estimate. Thank you for the help in advance..

<?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>

Upvotes: 0

Views: 1558

Answers (1)

Raythe
Raythe

Reputation: 472

Your loop doesn't append to $TileNameList because it exists outside of it. It actually replaces it's value. Try:

<?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>

Upvotes: 1

Related Questions