Hi all, Here is what I am trying to do:
Basicly I want to get the information from all rows in the database and output them into a form. It would display all the information e.g. title stuff like that but only the sort field will be editable. I have read that an array would do this? but to be honest I dont even know where to start. Also i would like it to be editable then update using 1 submit button that update all records. I have also attached an image showing what is looks like. Please note the title part would be from the database e.g. Image 1. Thanks all.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sort Order System</title>
<?php $area = $_GET['area']; ?>
<?php
include('db_connect.php');
$db=opendatabase();
?>
</head>
<body>
<?php
$sql="SELECT id,title,sort_order FROM gallery WHERE area=$area ORDER BY sort_order ASC;";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Title</strong></td>
<td align="center"><strong>Sort Order</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td><? echo $rows['title']; ?></td>
<td><input name="sort_order[]" type="text" id="sort_order" value="<? echo $rows['sort_order']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE gallery SET sort_order='$sort_order[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:sort.php");
}
mysql_close();
?>
</body>
</html>
I am using the above code at the moment, it displays the information i want but when i submit the pages just does nothing without changing the values i think this is because its using register globals which i have never used before as i normally use super globals as they are more secure, well so i have read. Should i be using an array for this? I dont even know where to begin using arrays. Any help would be great. Thanks.