I have the following snippet of code:
<li>
<label>Engine Size:</label>
<select name="engine">
<?php
$sql = mysql_query("SELECT DISTINCT BikeEngine FROM bikes "
. "ORDER BY BikeEngine ASC");
while ($row = mysql_fetch_array($sql)) {
echo "<option>" . $row['BikeEngine'] . "cc" . "</option>";
}
?>
</select>
</li>
My main issue is that the engine size is stored as an int in the database field but I want to add the cc on the end in the dropdown box as a suffix, but when the query is ran, it searches for say 1500cc and returns no results because it is stored as 1500 in the database field.
I was wondering how I'd go about resolving this?
Model:
public function searchBikes($brand, $engine)
{
if ($engine=='Any' || $brandString=='Any')
{
$this->db->select('BikeEngine');
$this->db->select('BikeMake');
$query = $this->db->get('bikes');
}
else
{
$this->db->like('BikeEngine', $engine);
$this->db->like('BikeMake', $brand);
}
$query = $this->db->get('bikes');
return $query->result();
}
Controller:
function search() {
$this->load->helper(array('form', 'url')); //without this form will not display
if ($this->input->post())
{
$brand = $this->input->post('brand');
$engine = $this->input->post('engine');
$this->load->model("mbikes");
$data['results'] = $this->mbikes->searchBikes($brand, $engine);
$this->load->view('searchresults.php', $data);
}
else
{
$this->load->view('search.php'); //display success view
}
}
选项值可以与其显示不同:
echo "<option value=". $row['BikeEngine'] .">" . $row['BikeEngine'] . "cc" . "</option>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.