473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Foreach() Question

I've been trying for 2 days now to solve this problem, which should be
pretty simple, but it is turning off to not be as simple.

I am trying to pull data out from a form that was POSTed on a previous
page. The code that I have that works is below:

<?php
for ($i = 2; $i <= $stoped; $i++) {
echo '<tr>'
.'<td>Step '."$i".'</td>'
.'<td>Input X</td>'
.'</tr>' ;
}

What I need to do is replace "Input X" with $step1, $step 2, ect..
until $stoped is reached. Before this code I added lines such

$step2 = $_POST["step2"] ;
$step3 = $_POST["step3"] ;
$step4 = $_POST["step4"] ;

to try to isolate the problem. I would perfer to be able to put
$_POST["step2"] directly in the for loop. All of my tries though
ened up with me just printing the line and not pulling the data from
the form.

I was also looking at foreach() and thought this might be what I am
looking for. Something that will loop through the $_POST array.
However what I have tried so far has not worked.

--
Any help would be greatly appreciated
Thanks
Blaine Hilton
Jul 16 '05 #1
5 2715
Filippov Alexander:
P.S.: Don't use "echo" - it's a bad style, use "print" - it's better.
Or, you can just close PHP tags and write html.


Huh? What's bad style about echo?

André Næss
Jul 16 '05 #2
uws
I <5b**************************@posting.google.com >, Filippov Alexander skrev:
P.S.: Don't use "echo" - it's a bad style, use "print" - it's better.


Why is `print' better? print() always returns true, echo doesn't return
anything. AFAIK that's the only difference.

mvrgr, Wouter

--
uws mail uw*@xs4all.nl

but i must be too dumb to be proud :: coz i waited -- our lady peace
Jul 16 '05 #3
Thanks alot for that advice, it really worked well. I am using your
code now and have come up with another problem that perhaps you can
solve. The code I am using is:

$i = -1 ;
foreach ($_POST as $key => $value) {
If (strlen($value)>0 AND $key != "title" AND $key != "author"
AND $key != "submit" ) {
$E->writerange("sheet1","A1","$value");
}
$i++;
}
What I need to do is loop through all of the POST data and write it to
the sheet in cells that go A1, then A2, then B1, B2, C1, C2, D1, D2,
ect.... All the way to 100 possibilities. How would I even begin to
replace A1 in the line:

$E->writerange("sheet1","A1","$value");

with something that will change like that?

--
Thanks again
Blaine Hilton

PS. Also can you tell me more why you think print is better then echo
?


On 6 Jul 2003 03:29:51 -0700, al*******@filippov.net (Filippov
Alexander) wrote:
Hi,

Try this:

$i = 2;
foreach ($_POST as $key => $value)
{
print '<tr>'.'<td>Step '.$i.'</td>'.'<td>'.$value.'</td>'.'</tr>';
$i++;
}

This should work - if not, write me, we'll make it work :)

P.S.: Don't use "echo" - it's a bad style, use "print" - it's better.
Or, you can just close PHP tags and write html.

---
Kindest regards,
Filippov Alexander

mailto: al*******@filippov.net
http://www.filippov.net

Jul 16 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Sun, 6 Jul 2003 13:42:20 +0200, uws
<uw*@xs4all.invalid> amazingly managed to produce the following with
their Etch-A-Sketch:
I <5b**************************@posting.google.com >, Filippov
Alexander skrev:
P.S.: Don't use "echo" - it's a bad style, use "print" - it's
better.


Why is `print' better? print() always returns true, echo doesn't
return anything. AFAIK that's the only difference.

mvrgr, Wouter

And because if this, is actually faster (although you'll probably
never physically see the difference without benchmarking).

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwhVk2fqtj251CDhEQKhNQCgqXaly3paaZDMvRTT10TNqM +X7+AAni4h
EQVEdGtMmpUJl5jJ/asEtTsw
=O7xs
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #5
uws
I <gb********************************@4ax.com>, Ian.H [dS] skrev:
Why is `print' better? print() always returns true, echo doesn't
return anything. AFAIK that's the only difference.

And because if this, is actually faster (although you'll probably
never physically see the difference without benchmarking).


I only use print() for debugging.

<?php $R = mysql_query("SELECT ..."); ?>

becomes:

<?php $R = mysql_query(print "SELECT ..."); ?>

or else the code will break.

mvrgr, Wouter

--
uws mail uw*@xs4all.nl

no more kill :: no more kill i'm in love -- black rebel motorcycle club
Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
13
by: cody | last post by:
foreach does implicitly cast every object in the collection to the specified taget type without warning. Without generics this behaviour had the advantage of less typing for us since casting was...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
8
by: Brad Wood | last post by:
When I do this: foreach( Button btn in myForm.Controls ) An exception is raised when no buttons exist. I would simply expect execution to continue after the foreach loop (just as would be the...
13
by: Michael Brown | last post by:
Hi there. Can anybody comment on the efficiency of the following technique: foreach (SomeItem Item in SomeNativeDotNet.Collection) { // Whatever } My concern is that the "Collection"...
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
9
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? ...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
7
by: Tony Johansson | last post by:
Hello! Why does not this cause a compile error because a ulong has never been implicitly convertible to byte? ulong vektor = {100000,200000,300000}; foreach(byte b in vektor) {...
1
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.