what I'm trying to do is, i have a table named hotels and i have a page where peoples can book the hotel based on the room category. now for displaying the hotels I am using a while loop in which datas are fetch and hotels are displayed in automated divs which id same for all. so i added a $i=1
and added to the id fields and $i
is incremented at the end of the while loop.
so what error I am getting is I am not able to retrieve the cost of the room category.
here is my code:
php code for getting individual hotels and show it in a div.
<?php
include 'mysql.php';
$i = 1;
$query = mysql_query("SELECT * FROM hotels WHERE location = 'portblair' ") or die("the query cannot be completed at this moment");
if(mysql_num_rows($query) <1) {
die("no hotels found");
}
while($row = mysql_fetch_array($query, MYSQL_ASSOC)){
$hotel_name = $row['name'];
$hotel_type = $row['type'];
$hotel_location = $row['location'];
$hotel_cat1 = $row['cat1'];
$hotel_cat2 = $row['cat2'];
$hotel_cat3 = $row['cat3'];
$hotel_cat4 = $row['cat4'];
$hotel_cp = $row['cp'];
$hotel_map = $row['map'];
$hotel_ap = $row['ap'];
$hotel_em = $row['em'];
if($hotel_type == "0"){
$hotel_star ='<span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span>';
}
if($hotel_type == "1"){
$hotel_star ='<span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span>';
}
if($hotel_type == "2"){
$hotel_star ='<span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span>';
}
if($hotel_type == "3"){
$hotel_star ='<span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span><span class="glyphicon glyphicon-star-empty"></span>';
}
if($hotel_type == "4"){
$hotel_star ='<span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span>';
}
?>
<div class="col-md-3 col-xs-6">
<div class="panel panel-red">
<div class="panel-heading">
<?php echo $hotel_name; ?>
</div>
<div class="panel-body">
<img src="images/hotels/<?php echo $hotel_name ?>.png" class="img-responsive"/>
<div class="my-caption">
<?php echo $hotel_star; ?>
</div>
<select name="hotel_cat" id="hotel_cat[<?php echo $i; ?>]" class="form-control" onchange="hotel_rate()">
<option value="">Category</option>
<?php if($hotel_cat1 != ""){
?>
<option value="<?php echo $hotel_cat1; ?>"><?php echo $hotel_cat1; ?></option>
<?php
} ?>
<?php if($hotel_cat2 != ""){
?>
<option value="<?php echo $hotel_cat2; ?>"><?php echo $hotel_cat2; ?></option>
<?php
} ?>
<?php if($hotel_cat3 != ""){
?>
<option value="<?php echo $hotel_cat3; ?>"><?php echo $hotel_cat3; ?></option>
<?php
} ?>
<?php if($hotel_cat4 != ""){
?>
<option value="<?php echo $hotel_cat4; ?>"><?php echo $hotel_cat4; ?></option>
<?php
} ?>
</select>
<span id="add[<?php echo $i; ?>]" >Add</span>
</div>
</div>
</div>
<?php
$i++;
}
?>
<input type="hidden" name="count" id="count" value="<?php echo $i; ?>"/>
so i want a js script that shows the cost of the category of room selected for individual hotels.
here is my js code:
function hotel_rate(){
jQuery(document).ready(function($){
var i=1;
var cnt = $("#count").val();
for(i=1;i<cnt;i++){
var cat = $("#hotel_cat["+i+"]").val();
var test = cat.split(:);
var cat_cost = parseInt(test[1]);
$("#add["+i+"]").html("Rs: "+cat_cost+" Add");
}
});
}
and the error iam getting from console is: "Uncaught ReferenceError: hotel_rate is not defined" and "Uncaught TypeError: Cannot read property 'split' of undefined".
any type of help would be appriciated. thanx in advance.
</div>