Im tyring to make a simple CMS page, basicly theres a table called 'settings', and a number of rows each one has an id and a short name of the setting (ie "showhits") the colomn across is 'status' -has either 1 or 0 (ie on or off).
My first page loops while getting the data from settings, this way I could have any number of options in my table. Then it creates a table and depending if it is set to 1 or 0 it will have a check box already checked or not. then next part is where Im stuck.
I just cant rap my brain around how to put this into an array for the next page to UPDATE the same row. Basicly I want the key in the array to be the id and the value to be the new status (or if nothing was changed the same status).
I must admit my Array skills require some work but after testing Associative Arrays it still seems hard code right.
--settings page--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Expires" CONTENT="Wed, 16 MAY 1996 14:00:00 GMT">
<title>RXmaz Rotary - Update settings</title>
<meta http-equiv="no-cache">
</head>
<?
//sets varibles for username etc
include "db.php";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM settings";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Update settings</center></b><br><br>";
?>
<body>
<p>Do no press the back button, use this menu</p>
<? include "admenu.php"; ?>
<tr>
<th><font face="Arial, Helvetica, sans-serif">Setting</font></th>
<th><font face="Arial, Helvetica, sans-serif">Status</font></th>
<th><font face="Arial, Helvetica, sans-serif">*</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$setting=mysql_result($result,$i,"setting");
$status=mysql_result($result,$i,"status");
?>
<form action="upsettingsnar.php" method="post">
<?
//sets color and ON/OFF from value of $status
if ($status == 1)
{ $light="#00FF00";
$state="ON"; }
else {$light="#FF0000";
$state="OFF";}
echo $id;
echo $status;
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><input name="id[]" type="hidden" value="<? echo $id; ?>"><? echo $setting; ?></font></td>
<td bgcolor="<? echo $light; ?>"><font face="Arial, Helvetica, sans-serif"><? echo $state; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? if ($status == 1)
{ ?> <input type="checkbox" name="status[]" value="1" checked> <? ; }
else
{ ?> <input type="checkbox" name="status[]" value="0"> <? ; }
?>
</font></td>
</tr>
<?
$i++;
}
?>
<p></p>
<p><input type="Submit" value="update"></p>
</form>
</body>
</html>
--update page--
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
Settings updated
<?php
//sets varibles for username etc
include "db.php";
//connects to db
mysql_connect(localhost,$username,$password);
//selects db
@mysql_select_db($database) or die( "Unable to select database");
$id=($POST['id']); //takes the data from a post operation...
$status=($POST['status']); //takes the data from a post operation...
//not sure what to do at this stage, should I have 2 mysql_querys? (one for 1-on and one for 0-off??)
//or could I use an array for the query to work through?
foreach( $status as $key=>$val){
print "$key = $val<br />";
}
//$query = "UPDATE settings SET status=1 WHERE id=$key" or die( "Unable to update settings");
//mysql_query($query);
//}
mysql_close();
?>
<body>
</body>
</html>
Thanks for any feed back at all, even just a good link on Arrays will be apreciated.