PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Sat Jul 22, 2006 7:26 pm
ok, ive created a simple code but its not EXACTLEY what i want, maybe someone can help me.
Code: Select all
<?php
$value = "5";
$db = mysql_connect("", "", "");
mysql_select_db("bhdsig",$db);
$result = mysql_query("SELECT * FROM pid ORDER BY pid", $db)or die("Error: ".mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$pid = $row['pid'];
echo "<FORM NAME='Name_01' ACTION='options.php' METHOD='POST'>
<input type='hidden' NAME='S1' VALUE='". $value ."'>
<input type='hidden' NAME='S2' VALUE='". $value ."'>
<input type='hidden' NAME='S3' VALUE='". $value ."'>
<input type='hidden' NAME='S4' VALUE='". $value ."'>
<input type='hidden' NAME='S5' VALUE='". $value ."'>
<input type='hidden' NAME='S6' VALUE='". $value ."'>
<input type='hidden' NAME='S7' VALUE='". $value ."'>
<input type='hidden' NAME='S8' VALUE='". $value ."'>
<input type='hidden' NAME='S9' VALUE='". $value ."'>
<input type='hidden' NAME='Background' VALUE='Afghanistan'>
<input type='hidden' NAME='TextColor' VALUE='Black'>
<input type='hidden' NAME='FontStyle' VALUE='Arial'>
<input type='hidden' name='oncethrough' value='Yes'>
<input type='hidden' name='playerid' value='". $pid ."'>
<input class='black' type='submit' name='submit' value='Change The Sig'>
</FORM>";
}
?>
currently what this is doing is making a new form for each $pid in the database, thats not what i want.
I want to press the "Change The Sig" once button and it iterate the same script for all $pid's in the database, i'd say it has something to do with the placement of the loop, but im not sure where exactley where to place it.
Any help is appreciated.
Thank You.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sat Jul 22, 2006 7:35 pm
everything within your while{} will get duplicated for each iteration of the loop.
if you don't want stuff duplicated, pull it out of the while{} and put it before or after.
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Sat Jul 22, 2006 7:42 pm
thank you for your reply, but i am aware of that. however, im unsure what i want to be duplicated to accomplish this task
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sat Jul 22, 2006 7:44 pm
then you're going to need to restate your orignial question as I am very confused when I read it...
SidewinderX
Forum Contributor
Posts: 407 Joined: Fri Jul 16, 2004 9:04 pm
Location: NY
Post
by SidewinderX » Sat Jul 22, 2006 8:07 pm
hm ok ill try...
the code as is displays 10 different submit buttons, 1 submit button for each value in the database, and of course this is because the entire code is looped....
I just want 1 submit button that when pressed will post this information to options.php for each value in the database
<input type='hidden' NAME='S1' VALUE='". $value ."'>
<input type='hidden' NAME='S2' VALUE='". $value ."'>
<input type='hidden' NAME='S3' VALUE='". $value ."'>
<input type='hidden' NAME='S4' VALUE='". $value ."'>
<input type='hidden' NAME='S5' VALUE='". $value ."'>
<input type='hidden' NAME='S6' VALUE='". $value ."'>
<input type='hidden' NAME='S7' VALUE='". $value ."'>
<input type='hidden' NAME='S8' VALUE='". $value ."'>
<input type='hidden' NAME='S9' VALUE='". $value ."'>
<input type='hidden' NAME='Background' VALUE='Afghanistan'>
<input type='hidden' NAME='TextColor' VALUE='Black'>
<input type='hidden' NAME='FontStyle' VALUE='Arial'>
<input type='hidden' name='oncethrough' value='Yes'>
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jul 22, 2006 8:18 pm
What are the field names in the table?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jul 22, 2006 8:19 pm
so move the submit button out of the loop.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Jul 22, 2006 8:38 pm
This is a quick example of what I think your trying to do.. I haven't tested it and I have no clue if it will work for you or not..
It will need to be modified to suite your needs.
Code: Select all
<?php
if ((isset($_POST['submit'])) AND ($_POST['submit'] == 'Change The Sig'))
{
foreach ($_POST as $key => $value) // loop through all the post variables
{
if (substr_count($key, '|') == 1) // check if it has a pipe in it..
{
// there is a pipe in it..
list($RecordID, $FieldName) = explode('|', $key); // get the record number and the field name
// insert this into an array..
$NewValues[$RecordID][$FieldName] = $value;
}
}
// now insert the new values into the database..
foreach ($NewValues as $RecordID => $Record)
{
$Query = "UPDATE `TABLENAME` SET "; // start building the query
foreach ($Record as $FieldName => $value)
{
$Query .= "`" . mysql_real_escape_string($FieldName) . "`='" . mysql_real_escape_string($value) . "', ";
}
$Query = substr($Query, 0, -2);
$Query .= " WHERE `ID`='" . mysql_real_escape_string($RecordID) . "' LIMIT 1";
$result = mysql_query($Query); // execute the query..
}
}
$value = "5";
$db = mysql_connect("", "", "");
mysql_select_db("bhdsig",$db);
$result = mysql_query("SELECT * FROM pid ORDER BY pid", $db)or die("Error: ".mysql_error());
echo "<FORM NAME='Name_01' ACTION='options.php' METHOD='POST'>";
while ($row = mysql_fetch_assoc($result))
{
$pid = $row['pid'];
echo
"<input type='hidden' NAME='" . $row['ID'] . "|S1' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S2' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S3' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S4' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S5' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S6' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S7' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S8' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|S9' VALUE='". $value ."'>
<input type='hidden' NAME='" . $row['ID'] . "|Background' VALUE='Afghanistan'>
<input type='hidden' NAME='" . $row['ID'] . "|TextColor' VALUE='Black'>
<input type='hidden' NAME='" . $row['ID'] . "|FontStyle' VALUE='Arial'>
<input type='hidden' name='" . $row['ID'] . "|oncethrough' value='Yes'>
<input type='hidden' name='" . $row['ID'] . "|playerid' value='". $pid ."'>";
}
echo "<input class='black' type='submit' name='submit' value='Change The Sig'>";
echo "</FORM>";
?>