data grid and mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
danger
Forum Newbie
Posts: 2
Joined: Thu Oct 09, 2003 1:10 pm

data grid and mysql

Post by danger »

Hy,

I`m pretty new in PHP, and I have a little problem,
how can I update data from a mysql table using a grid ?

If I have two ore more records, how can I update them ?

I know how to pull the dat out from the database, but I don`t know hot to put it back.


Thanks
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

do you have a field called ID or a field which is unqiue to each record?

if so, put use that...here is a example:

Code: Select all

<?php
$query = mysql_query("select ID, name from table");
while($row = mysql_fetch_array($query))
{
echo "[<a href="edit.php?id=$row[ID]">Edit</a>]$row[name]<br />";
}
?>
?>
edit.php

Code: Select all

<?php
//update
if(isset($_POST[ready]))
{
$update = mysql_query("update table set name='$_POST[name]' where ID =$id limit 1");
echo "UPDATED...";
}
//form
$id = (int)$_GET['id'];
$data = mysql_fetch_array(mysql_query("select name from table where ID = $id"));
echo "<form method=post action="?id=$id">
NAME: <input type="text" value=""><br />
<input type="submit">
<input type=hidden name=ready value=$id>
</form>";

?>
danger
Forum Newbie
Posts: 2
Joined: Thu Oct 09, 2003 1:10 pm

Post by danger »

10x
Post Reply