Help updating multiple rows in a MySQL table

I am very (very) new to PHP and was looking to get pointed in the right direction on how update multiple records on one page, once the update button is selected. Basically I want to present a table which shows information about a list of users, the table will have username, email address, age, home address, telephone number. This will have only ten users listed. For example I want to update a users age click update and the table gets updated. Any help would be great.

Hi Chris,

I’m a newbie, too, so I probably don’t know what I’m talking about but still willing to give an opinion.

I worked through a tutorial at:
http://www.freewebmasterhelp.com/tutorials/phpmysql/
(I hope it’s OK to post their site) on CONTACTS DATABASE by David Gowans

As I understand what you are describing, You will be updating all values of your matrix.
That seems cumbersome as you will have to have an input field for every matrix position. I assume that you would set up loops to go through and update each value of each row.

In working with the above exercise, I set the update to be on values of individual rows, rather than the whole table at once.

To use php-MySQL, I set up an index page, as below. The index page calls the scripts in the above tutorial. This index includes a field for photo but it is only for a filename and does not upload the photo.

Here’s the index page that calls the tutorial scripts:

[php]

<? include("dbinfo.inc.php"); // database connection info $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo " Database Output

"; ?> <? $i=0; while ($i < $num) { $row=mysql_result($result,$i,"id"); $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); $photo=mysql_result($result,$i,"photo"); ?> <? ++$i; } echo "
Photo Name Phone Mobile Fax E-mail Website Update
<? echo "$photo"; ?> <? echo "$first $last"; ?> <? echo "$phone"; ?> <? echo "$mobile"; ?> <? echo "$fax"; ?> ">E-mail ">Website ">{update] ">{DELETE]!!


[ADD RECORD]
"; ?>

[/php]

This allows you to select one row to update and update all fields of that row. Your description sounds much more ambitious than my simple approach.

This table lists all values in the database. If you have a large number of entries, you may want to break the display loop.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service