shrive22 Posted June 26, 2009 Share Posted June 26, 2009 I have a table called groups with just an id and description. The main page is just an html table that lists the id's and descriptions on each row with a link to 'edit' and 'delete' that record. So far my update/edit page works so long as the primary key does not change during the update. I am passing the record information from my main page to the update page with $_GET. I am wondering if passing the record data to the update/edit page by $_SESSION variable is better (I have more mysql tables that have more fields in them) and the best way to do that. I tried to assign record variables to the $_SESSION variables but it only returns the last record in the table. My code below: <?php if($_GET['sortby']) { $orderby = $_GET['sortby']; } else { $orderby = "groupid"; } $query = "SELECT * "; $query .= "FROM groups "; $query .="ORDER BY ".$orderby; echo "<p><h3>mySQL query is : " .$query."</h3></p><br /><br />\n"; // 3. perform the database query $group_set = mysql_query($query, $connection); confirm_query($group_set); $numrows = mysql_num_rows($group_set); if($numrows ==0) { echo "Sorry. No Records Found!!"; } else if ($numrows>0) { $i = 0; //echo "<br /> {$numrows} results were retrieved from the table.\n"; echo "<table>\n"; echo "<tr><th colspan=\"2\"><a href=\"add_group.php\">Add New Group</a></th>\n <th></th>\n <th><a href=\" {$PHP_SELF} ?sortby=groupid\">Group ID</th>\n <th><a href=\" {$PHP_SELF} ?sortby=description\">Description</th> </tr>\n"; while ($group = mysql_fetch_array($group_set)) { if (($i%2)==0) {$bgcolor = "#FFFFFF";} else {$bgcolor = "#C0C0C0";} echo "\t<tr BGCOLOR=\"{$bgcolor}\">\n"; echo "\t<td><a href=\"edit_group.php?groupid=" . urlencode($group['groupid']) . "&description=" . urlencode($group['description']) . "\">Edit</a></td>\n"; echo "\t<td><a href=\"delete_group.php?groupid=" . urlencode($group['groupid']) . "\" onclick=\"return confirm('Are you sure you want to delete Group: " . $group['groupid'] . "');\">Delete</a></td>\n"; echo "\t<td> {$i} </td>\n"; echo "\t<td> {$group["groupid"]} </td>\n"; echo "\t<td> {$group[description]} </td>\n"; echo "\t</tr>\n"; $i++; } // end of while ($i<$numrows) echo "</table>\n<br>"; } // end of else if ($numrows>0) mysql_data_seek($group_set, 0); $numrows = mysql_num_rows($group_set); if($numrows ==0) { echo "Sorry. No Records Found!!"; } else if ($numrows>0) { echo "<br /> {$numrows} results were retrieved from the table.\n"; } ?> any ideas appreciated thanks Link to comment https://forums.phpfreaks.com/topic/163784-update-mysql-record-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.