Thank you, Jeromie, for the useful explanation. Let me
clarify the problem Im having a bit more:
I retrieve rows of data from tables and display them
in html TABLE format. Each operation retrieves the
rows as an array, which I then use foreach ($row as
$value) to print on the screen.
Now this works fine but the screen also has other
graphics, buttons, etc. What I want to do is to add a
button where a user can click and the SAME array of
data is retrieved again but displayed, this time, in
comma-separated rows. It has been a big challenge for
me. The only way I could think of is to have a hidden
field in a form with the new submit button I want to
add, like so:-
<form action =
'display_as_comma_separated_fields.php'>
<input type = 'hidden' name = 'rows' value = '$row'>
<input type = 'button' name = 'submit' type =
'submit'>
</form>
Note the value of the hidden field i.e. $row. This
$row is the array already retrieved from the database
table.
Then, I thought, I could post it to the other php page
and process it again, using "foreach". In theory this
seemed perfectly okay but when I do it like this:-
#on page: 'display_as_comma_separated_fields.php' #
$rows = $_POST['rows']; // the array passed in the
hidden field
if ($submit)
{
foreach ($rows as $value)
{
echo $value[0] . ',' $value[1] . ','$value[2] .
'<br>';
}
}
For some reason, I get the error:
Warning: Invalid argument supplied for foreach()..
.. and for the life of me I cant see why !!!
Any suggestion? Many thanks
--- Jeromie Clark <[EMAIL PROTECTED]> wrote:
---------------------------------
It's hard without some context, but I'm guessing that
you should be
looking for your post results in the global $_POST
variable, but you're not.
Example:
You've got a form, with an element called "item":
<form method='POST' action='target_url.php'>
<input type='text' name='item'>
<input type='submit' value='Go >>'>
On your target page, the value from the form is going
to be in the
$_POST array.
example:
echo $_POST['item'];
Also, if you need to post an array of data via a form,
you can have
multiple elements with the same name.
This is commonly used for checkboxes, where you can
have multiple
specified values for one field:
<form method='POST' action='target_url.php'>
<input type='checkbox' name='colors[]' value='red'>
<input type='checkbox' name='colors[]' value='blue'>
<input type='checkbox' name='colors[]' value='green'>
</form>
The '[]' at the end of the name tells PHP to compile
all the values into
an array for you.
Then, you could do:
foreach($_POST['colors'] AS $color) {
echo $color . ",";
}
Hope that helps,
Jeromie
>Hello
>I have this problem that seems at the surface dead
>easy .., yet ive been struggling with it for a couple
>of days
>
>Id like to give users the option of saving selected
>data by clicking on a button. When this is done, the
>same rows would be displayed but this time with
>comma-separated values, and nothing else. No graphics
>or other options/buttons on the screen. Then a user
>would simply save the page as text or html.
>
>What I have been trying to do without success, is to
>post the array in a hidden field to another page.
And
>then try :
>foreach ($array as $value){
>
>etc..}
>
>But for some reason that has not worked for me. I
>keep gettin the error :
>Warning: Invalid argument supplied for foreach() ..
>
>Your suggestions are greatly appreciated,
>
>David
>
>
>
>
>
>___________________________________________________________
>Yahoo! Messenger - NEW crystal clear PC to PC calling
worldwide with voicemail http://uk.messenger.yahoo.com
>
>
>The php_mysql group is dedicated to learn more about
the PHP/MySQL web database possibilities through group
learning.
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
The php_mysql group is dedicated to learn more about
the PHP/MySQL web database possibilities through group
learning.
SPONSORED LINKS
American general life and accident insurance company
American general life
insurance company
American general life
American general
mortgage American
general life insurance
Computer internet security
---------------------------------
YAHOO! GROUPS LINKS
Visit your group "php_mysql" on the web.
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
Your use of Yahoo! Groups is subject to the Yahoo!
Terms of Service.
---------------------------------
___________________________________________________________
Yahoo! Photos NEW, now offering a quality print service from just 8p a photo
http://uk.photos.yahoo.com
The php_mysql group is dedicated to learn more about the PHP/MySQL web database
possibilities through group learning.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php_mysql/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/