You are not logged in.

#1 2006-10-16 09:56:21

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

PHP array

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

#2 2006-10-16 10:27:22

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

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

#3 2006-10-16 12:33:22

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: PHP array

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

#4 2006-10-16 12:56:53

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

foreach ($array as $item)
  echo $item;

to live is to die

Offline

#5 2006-10-16 13:04:00

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

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

#6 2006-10-21 08:58:12

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: PHP array

Romashka wrote:

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

#7 2006-10-21 09:34:10

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

rasat wrote:

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

#8 2006-10-21 09:35:09

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

From PHP Manual:

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

#9 2006-10-21 12:04:01

rab
Member
Registered: 2006-06-15
Posts: 185

Re: PHP array

print_r($yourarray);

rawr

Offline

#10 2006-10-23 09:24:18

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: PHP array

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. lol 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

#11 2006-10-23 10:34:26

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

rasat wrote:
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. lol

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:

wink
Even in Language Reference - Types - Arrays there's no mention of list/each way, only foreach. wink 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).

rasat wrote:

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! smile

rasat wrote:

Thanks, for the simpler format.

You are welcome! smile

BTW, you are forum and wiki admin, but who maintains their code? dtw?


to live is to die

Offline

#12 2006-10-24 17:55:26

rasat
Forum Fellow
From: Finland
Registered: 2002-12-27
Posts: 2,296
Website

Re: PHP array

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).

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


Markku

Offline

#13 2006-10-24 19:15:32

Romashka
Forum Fellow
Registered: 2005-12-07
Posts: 1,054

Re: PHP array

rasat wrote:
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?

rasat wrote:
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  tongue  )
Anyway that doesn't matter now when you know how to use foreach. wink


to live is to die

Offline

Board footer

Powered by FluxBB