sorry if my question-title is confusing..i don't know exactly how to put it. but here's what:
so..im trying to get the data in my database, put it in
<select><option>
tag. and echo it.
addtocart.php this is my first code and this is working fine, with preset values
<?php
define('INCLUDE_CHECK',1);
require "../connectDB.php";
if(!$_POST['img']) die("There is no such product!");
$img=mysql_real_escape_string(end(explode('/',$_POST['img'])));
$row=mysql_fetch_assoc(mysql_query("SELECT * FROM rooms_addons WHERE img='".$img."'"));
echo json_encode(array(
'status' => 1,
'id' => $row['id'],
'price' => (float)$row['price'],
'txt' => '<table width="65%" id="table_'.$row['id'].'">
<tr>
<td width="5%" style="display:none;"><input type="text" name="id[]" value="'.$row['id'].'" style="width: 28px; border-width: 0px;"></td>
<td width="35%"><input type="text" name="roomname[]" value="'.$row['name'].'" style="width: 95px; border-width: 0px;"></td>
<td width="20%">Php <input type="text" name="price[]" value="'.$row['price'].'" style="width: 40px; border-width: 0px;"></td>
<td width="15%"><select name="qty[]" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');" style="width: 40px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></select>
</td>
<td width="15%"><a href="#" onclick="window.remove('.$row['id'].');return false;" class="remove">remove</a></td>
</tr>
</table>'
));
?>
now my problem is that, like what i've said, i want to put the "quantity" numbers (which is in my database table) in the
<select><option>
..with that here's what i've done:
<?php
define('INCLUDE_CHECK',1);
require "../connectDB.php";
if(!$_POST['img']) die("There is no such product!");
$img=mysql_real_escape_string(end(explode('/',$_POST['img'])));
$row=mysql_fetch_assoc(mysql_query("SELECT * FROM rooms_addons WHERE img='".$img."'"));
echo json_encode(array(
'status' => 1,
'id' => $row['id'],
'price' => (float)$row['price'],
'txt' => '<table width="65%" id="table_'.$row['id'].'">
<tr>
<td width="5%" style="display:none;"><input type="text" name="id[]" value="'.$row['id'].'" style="width: 28px; border-width: 0px;"></td>
<td width="35%"><input type="text" name="roomname[]" value="'.$row['name'].'" style="width: 95px; border-width: 0px;"></td>
<td width="20%">Php <input type="text" name="price[]" value="'.$row['price'].'" style="width: 40px; border-width: 0px;"></td>
<td width="15%">
$qty = $row["qty"];
<select name="'.$row['id'].'_cnt" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');">
for ($i=0;$i<=$qty;$i++) {
<option>' . $i . '</option>
}
</select>
</td>
<td width="15%"><a href="#" onclick="window.remove('.$row['id'].');return false;" class="remove">remove</a></td>
</tr>
</table>'
));
?>
my for-loop alone works well, but when i put that in echo json_encode, in addtocart.php the whole addtocart.php doesnt work.
i used the for-loop for select-option coz it is for quantity to be displayed in dropdown, like if whats in the database is 5 then it would appear as 1 2 3 4 5 in dropdown.
i don't know how to fix my code and i can't think of any other thing to replace the dropdown for selecting quantity of products/item with regards to my database data :( any suggestions? ..thanks in advance