Closed Thread Icon

Topic awaiting preservation: Mysql and php with multiple entrys (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13028" title="Pages that link to Topic awaiting preservation: Mysql and php with multiple entrys (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Mysql and php with multiple entrys <span class="small">(Page 1 of 1)</span>\

 
Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 01-06-2004 17:27

Ok I have a database wit hthe coloums Rank,Name,Block,Home, ID

now in my adminstration panel I pull out everyone who 's on the same block and have a form the form has there name,block,rank,home in a editable input field,
a row for each person so the entrys the admin would like to change can be changed and the others can be left the same and the user can simply press 'update' now..

too get my multiple lines of inputs im using this code,

code:
$query =  mysql_query("SELECT * FROM staff WHERE block = '$block' ORDER BY 'block'") or die(mysql_error());

print "<table>";
print "<form action=\"$_SERVER[PHP_SELF]?block=$_GET[block]\" method=\"post\">";
while($data = mysql_fetch_array($query)){
?>
<tr>
<td><input type="text" name="name" value="<?php print $data['name']; ?>"></td>
<td><input type="text" name="homeurl" value="<?php print $data['home'];?>"></td>
<td><input type="text" name="block" value="<?php print $data['block'];?>"></td>
<td><input type="text" name="block" value="<?php print $data['rank'];?>">
<input type="hidden" name="id" value="<?php print $data['id']; ?>"></td>
</tr>
<?
}
print "<tr>\n<td><input type=\"submit\" value=\"submit\" name=\"submit\"></td>\n</tr>\n";
print "</form>";
print "</table>";



Now. . how do I insert all the data back into the table the easiest with out re-writing over anything else? keeping the id's wit hthe relivant posts etc.. I really cant seem to figure it out i've tried multiple things.. but its just not happening for me

can some one please help me

Trigger

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-06-2004 17:34

The issue here is mainly an HTML one.

You can't have input text fields with the same name otherwise you're going to break your form. (The last entry clobbers all the rest I believe ).





.:[ Never resist a perfect moment ]:.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-06-2004 17:54

Rhather than use a hidden field to state the ID, I would append the ID to the name of each field. That way, each input has a unique name, and you can parse the name string to get the ID when entering the info back in to the database.

so, for each input, the name would be (for example) name_00037, rank_00037, etc....




Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 01-06-2004 18:01

How would I then incorporate the updateing of table... in one query then?
I mean considering I'll be updateing the same coloums multiple times.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-06-2004 18:28

you can't. You'll have to make serveral update queries.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-06-2004 22:22

yeah, run a loop to query the DB for each ID.



« BackwardsOnwards »

Show Forum Drop Down Menu