I got it. Thanks guys. Here's the final code:
<!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>Untitled Document</title>
</head>
<body>
<form action="edit-process.php" method="post">
<?php
$con = mysql_connect ("localhost","USERNAME","PASSWORD"); // ready db connect
if(!$con){
die("could not connect". mysql_error());
}
mysql_select_db("vanilani_notebooks2",$con); // execute connect and select db
// Find highest ID number -- for when selecting/making the "new category"
$result = mysql_query("SELECT Category FROM Categories ORDER BY Category DESC LIMIT 1");
while ($row = mysql_fetch_assoc($result)) {
$h = $row['Category'];
}
// Find lowest ID number - to use to know when the ID's in the DB table has increased (and to <br /> and echo the next numbe)
$result = mysql_query("SELECT Category FROM Categories ORDER BY Category ASC LIMIT 1");
while ($row = mysql_fetch_assoc($result)) {
$l = $row['Category'];
}
$result = mysql_query("SELECT Categoryname FROM Categories ORDER BY Category ASC "); // ???
$stackcn = array();
// make array of "Categoryname" row
while ($row = mysql_fetch_assoc($result)) {
array_push($stackcn, $row['Categoryname']);
}
$result = mysql_query("SELECT * FROM Categories ORDER BY Category ASC"); // ???
$stack = array();
// make array of "category" row
while ($row = mysql_fetch_assoc($result)) {
array_push($stack, $row['Category']);
}
$result = mysql_query("SELECT * FROM Categories ORDER BY Category ASC"); // ???
$stack2 = array();
// make array of "ID" row
while ($row = mysql_fetch_assoc($result)) {
array_push($stack2, $row['ID']);
}
if (isset($l)){ // check if $l (the lowest number ID actually exists)
if ($stackcn[0] != ""){ // check if the first category has a name
echo "no: ".$l;
echo "<br />";
//echo "<span style='font-size:100px;'>".$stackcn[0]."</span>";
echo "<input type='text' name='Categorynames[".$l."]' value='".$l."' style='text-decoration:underline; color:red;' />
<input type='radio' name='Categorynamer' value='".$l."' />
<input type='submit' name='Rename' value='Rename' /> <br />";
echo "<br /><br />";
}else{
echo "no: ".$l;
echo "<br />";
echo "<span style='font-size:100px;'>".$l."</span>";
echo "<input type='text' name='Categoryname' value='".$l."' /> <input type='submit' value='Rename' /> <br />";
echo "<br /><br />";
}
}
/*
while ($row = mysql_fetch_assoc($result)) {
if($row['Category']>$l){
$l++;
echo "<br />";
echo "<span style='font-size:100px;'>".$l."</span>";
}
$string = $row['string'];
//echo $row['string']."<br />";
//echo "<input type='hidden' name='ID' value='".$row["ID"]."' />";
echo "<input type='text' name='string".$row['ID']."' value='".htmlentities($string,ENT_QUOTES)."' />";
echo "<input type='radio' name='string' value='".$row['ID'].",".htmlentities($string,ENT_QUOTES)."' /> <br />";
}
*/
$result = mysql_query("SELECT * FROM Categories ORDER BY Category ASC"); // ???
$stack3 = array();
// make array of "string" row
while ($row = mysql_fetch_assoc($result)) {
array_push($stack3, $row['string']);
}
//print_r ($stack);
//print_r ($stack2);
// print_r ($stack3);
$category = $l;
$count = 0;
foreach ($stack as $value){
if($value>$category){
$category = $value;//$stack[$count];
echo "<br />"."no: ".$category;
if($stackcn[$count] != ""){ // if category.. has a name
echo "<br />";
//echo "<span style='font-size:100px;'>".$stackcn[$category]."</span>";
// echo "<input type='text' name='Categoryname".$stackcn."' value='".$stackcn[$count]."' style='text-decoration:underline; color:red;' />
echo "<input type='text' name='Categorynames[".$category."]' value='".$stackcn[$count]."' style='text-decoration:underline; color:red;' />
<input type='radio' name='Categorynamer' value='".$category."' />
<input type='submit' name='Rename' value='Rename' /> <br />";
echo "<br />";
}if($stackcn[$count] == ""){
// echo "no: ".$category;
echo "<br />";
//echo "<span style='font-size:100px;'>".$category."</span>";
echo "<input type='text' name ='Categorynames[".$category."]' value='".$category."' style='text-decoration:underline; color:red;' />
<input type='radio' name='Categorynamer' value='".$category."' />
<input type='submit' name='Rename' value='Rename' /> <br />";
echo "<br />";
}
}
// echo $value;
$stringIDno = $stack2[$count];
$string = $stack3[$count];
echo "<input type='text' name='strings[" . $stack2[$count] . "]' value='".htmlentities($string,ENT_QUOTES)."' />";
echo "<input type='radio' name='string' value='".$stringIDno." ,".htmlentities($string,ENT_QUOTES)."' /> <br />";
//echo "<input type='radio' name='string' value='".$stack2[count].",".htmlentities($string,ENT_QUOTES)."' /> <br />";
$count++;
}
/*
$category = $l;
foreach ($stack2 as $value){
if($category>$l){
$category++;
echo "<br />";
echo "<span style='font-size:100px;'>".$category."</span>";
}
$string = $stack3[$value];
echo "<input type='text' name='string".$string."' value='".htmlentities($string,ENT_QUOTES)."' />";
echo "<input type='radio' name='string' value='".$string.",".htmlentities($string],ENT_QUOTES)."' /> <br />";
//echo $value;
}
*/
// loop/while, putting every string - from every row - into an array.. then can echo all the arrays
?>
<br /><br />
<input type="number" name="Category" value="" />
<input type="submit" value="Change category" />
<input type="submit" name="delete" value="Delete" src="edit-process.php" />
</form>
</body>
</html>
<!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>Untitled Document</title>
</head>
<body>
<?php
//$catinfo = explode(",", $_POST["Categorynamer"]);
//$catname = $catinfo[0];
//$catno = $catinfo[0];
// $catname = $catinfo[1];
// $catname = $_POST["Categoryname".$catno];
$delete = $_POST["delete"];
$Rename = $_POST["Rename"];
$Category = $_POST["Category"];
$Categorynamer = $_POST["Categorynamer"]; //category number
$stringinfo = explode(",", $_POST["string"]);
$stringID = $stringinfo[0];
$stringold = $stringinfo[1];
//echo $string = $_POST['strings']['$stringID'];
// get the name of the string textbox input tage
foreach ($_POST['strings'] as $key => $value){
if ($key == $stringID){
$string = $value;
}
}
// get the name of the categoryname textbox input tage
foreach ($_POST['Categorynames'] as $key => $value){
if ($key == $Categorynamer){
$categoryname = $value;
}
}
//$string = $_POST[$stringID];
//print_r(array_keys( $_POST ));
/*
foreach ($_POST as $key => $value){
if ($key == $stringID){
echo $key;
}
} */
//$string = $_POST["string".$stringID];
//$stringinfo = explode(",", $_POST["string"]);
//$string = $stringinfo[1];
//echo $string2ID = $stringinfo[0];
//echo $string2 = $_POST["string".$string2ID];
//$string2 = $_POST["string2"];
//$string2 = htmlentities($string2,ENT_QUOTES); // fix quotes on $string2
// $ID = $_POST["ID"];
//print_r(array_keys($$Categoryname));
//$Categoryrinfo = explode(",", $_POST["Categorynamer"]);
//$Categoryno = $Categoryrinfo[0];
//$Categorytext = $Categoryrinfo[1];
//$Categorytext2 = $_POST[$Categorytext];
//$Categoryname = $_POST["Categoryname".$Categoryno];
$con = mysql_connect ("localhost","USERNAME","PASSWORD"); // ready db connect
if(!$con){
die("could not connect". mysql_error());
}
mysql_select_db("vanilani_notebooks2",$con); // execute connect and select db
if(isset($delete)){ // if delete was selected
mysql_query("DELETE FROM Categories WHERE ID='".$stringID."'");
echo $string." <br /> Deleted";
}
if(isset($Rename)){ // if rename was pressed
mysql_query("UPDATE Categories SET Categoryname='".$categoryname."' WHERE Category='".$Categorynamer."'");
echo "Category No:".$Categorynamer." renamed to ".$categoryname;
}
if($Category != ""){ // or else, if a number was put in
//mysql_query("UPDATE Categories SET Category='".$Category."', string='".$string."' WHERE ID='".$stringID."'");
mysql_query("UPDATE Categories SET Category=".$Category.", string='".$string."' WHERE ID=".$stringID); // update DB
echo $string." <br /><br /> changed to category ".$Category;
}
?>
<br />
<a href="index.php">Go back</a>
</body>
</html>