You are not logged in.
Pages: 1
I have a page listing part numbers and each row one checkbox. When selected rows are tagged, press "Save" and MySQL is updated. How to create an array?
Each checkbox (row) has a different value.
$TickMark=$Tickmark + 1;
print <<<EOD
<td>
<INPUT type=checkbox name="CheckApp" value="$TickMark">
</td>
<td>$myrow[PartNo]
</td>
When "Save" button is pressed:
$checkapp=$_POST['CheckApp'];
if (issue($checkapp) && $checkapp !="") {
mysql_query("UPDATE StockReg SET OrderTick = '$checkapp' WHERE PartNo = 'partno'");
}
Markku
Offline
I don't completely understand what you want.
Do you want to create an array of all <input>s?
Then just add [] to their name:
name="CheckApp[]"
to live is to die
Offline
This is first time I am dealing with array in PHP, how to read (echo) the result? With a single variable, its "echo $checkapp". With an array?
Markku
Offline
foreach ($array as $item)
echo $item;
to live is to die
Offline
You have little experience in PHP, don't you? I suggest reading their official manual. It's much better than any other info I've seen, IMHO.
to live is to die
Offline
I suggest reading their official manual.
That's what I am reading, but often too much information to find what you want.
This is what I did. It works but I am looking for something simpler.
$appsave = $_POST['checkApp'];
//Remove existing tags
mysql_query("UPDATE StockReg SET OrderTick = ' ' WHERE 1");
reset($appsave);
while (list(, $value) = each($appsave)) {
mysql_query("UPDATE StockReg SET OrderTick = 'App' WHERE Sno = '$value'");
}
Markku
Offline
This is what I did. It works but I am looking for something simpler.
$appsave = $_POST['checkApp']; //Remove existing tags mysql_query("UPDATE StockReg SET OrderTick = ' ' WHERE 1"); reset($appsave); while (list(, $value) = each($appsave)) { mysql_query("UPDATE StockReg SET OrderTick = 'App' WHERE Sno = '$value'"); }
What a strange construct... Is it Perl/Python/Rubysh thing? :?
$appsave = $_POST['checkApp'];
//Remove existing tags
mysql_query("UPDATE StockReg SET OrderTick = ' ' WHERE 1");
foreach ($appsave as $value) {
mysql_query("UPDATE StockReg SET OrderTick = 'App' WHERE Sno = '$value'");
}
to live is to die
Offline
You may have noticed that the following are functionally identical:
$arr = array("one", "two", "three"); reset($arr); while (list(, $value) = each($arr)) { echo "Value: $value<br>n"; } foreach ($arr as $value) { echo "Value: $value<br>n"; }
BTW I just found a bug in phpBB - related to XML processing instructions ("?php") - they just cannot be written, in any form.
Which version of phpBB our forum uses now?
to live is to die
Offline
print_r($yourarray);
rawr
Offline
What a strange construct... Is it Perl/Python/Rubysh thing? :?
Copied from from php's official manual. You also recommended to read it, that's what an user may get when too much information. This is why I prefer instead Arch Forum (General Programming Forum) ... if not the direct answer but right direction for the solution.
Thanks, for the simpler format.
Markku
Offline
Romashka wrote:What a strange construct... Is it Perl/Python/Rubysh thing? :?
Copied from from php's official manual. You also recommended to read it, that's what an user may get when too much information.
Where did you read that?
Function Reference - Arrays - foreach
The right way is described here, and also
You may have noticed that the following are functionally identical:
Even in Language Reference - Types - Arrays there's no mention of list/each way, only foreach. So I'm curious why did you choose that way.
It's highly recommended to read Language Reference, Security and Features before Function Reference, and always have the latest version of PHP Manual with users' comments (or online).
This is why I prefer instead Arch Forum (General Programming Forum) ... if not the direct answer but right direction for the solution.
Arch Community is great!
Thanks, for the simpler format.
You are welcome!
BTW, you are forum and wiki admin, but who maintains their code? dtw?
to live is to die
Offline
Which version of phpBB our forum uses now?
BTW, you are forum and wiki admin, but who maintains their code? dtw?
Latest version, 2.0.21.
The system maintainer has been dtw but recently he handover it back to apeiro (Judd).
Where did you read that?
Its a list() funtion.
I couldn't retrace the exact location but somehere here:
http://www.php.net/manual/en/function.list.php
Markku
Offline
Romashka wrote:Which version of phpBB our forum uses now?
BTW, you are forum and wiki admin, but who maintains their code? dtw?Latest version, 2.0.21.
The system maintainer has been dtw but recently he handover it back to apeiro (Judd).
I remember dtw has posted a topic about moving to phpBB 3. Maybe you know why it hasn't been done?
Romashka wrote:Where did you read that?
Its a list() funtion.
I couldn't retrace the exact location but somehere here:
http://www.php.net/manual/en/function.list.php
There are nothing about using list and each simultaneously. Maybe it was outdated version, outdated user comment, or outdated non-English translation (it all happens sometime). I see many user comments about using foreach there. User comments are one of the coolest thing in PHP Manual. If they are not deleted (which happens when they are wrong) then there's high chance that they are valid (even for language bugs / cheats).
(yes, I know I can be boring sometimes )
Anyway that doesn't matter now when you know how to use foreach.
to live is to die
Offline
Pages: 1