Let's say I have a table with 10 records and I want to take name, lastname and rank from those 10 records. First I do something like this:
<?php // DATABASE SELECT QUERY
$db =& JFactory::getDBO();
$query="SELECT name, lastname, rank
FROM table
ORDER BY rank ASC";
$db->setQuery($query);
$rows = $db->loadObjectList(); ?>
Then, I add some fields in to my form that contain table's values, so I can edit them through form:
<form action="#" method="post" name="form">
<table><?php $count = 0; while ($count < 10){
$name = $rows[$count]->name;
$lastname = $rows[$count]->lastname;
$rank = $rows[$count]->rank; ?>
<tr>
<td><input name="name" value="<?php echo $name ?>" type="text" /></td>
<td><input name="lastname" value="<?php echo $lastname ?>" type="text" /></td>
<td><select name="rank">
<option value="<?php echo $rank ?>"><?php echo $rank ?></option>
<option disabled="disabled" value="...">...</option>
<?php for ($i = 0; $i <= 100; $i++){ ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option> <?php } ?>
</select></td>
</tr><?php $count++;}?>
</table>
<input class="something" name="updatemod" type="submit" value="UPDATE" />
</form>
Next, before Select query, I have add an update query using this method below, so when I press the update button, update my DB:
// DATABASE UPDATE QUERY
if (isset($_POST['updatemod']) or isset($_GET['updatemod'])){
$db =& JFactory::getDBO();
$query = "UPDATE table
SET name = '".$_POST["name"]."',
SET lastname = '".$_POST["lastname"]."',
SET rank = '".$_POST["rank"]."'
";
$db->setQuery($query);
$db->query();}
But... Nothing is working!!! I have done exactly the same thing for an other form and it's working perfect! The only difference between those two forms, is that I am not using this while
loop at the other form. So, maybe it has to do with this or something??? I don't know, at this point is where my knowledge confused, so I need your help!