Jump to content

Passing arrays

Recommended Posts

I'm working on a web page that keeps track of scores in the game Mah Jong.Each round users input their score into a form and press update scores. I have an array that keeps track of the score each round, total score, players names , etc. My problem is i'm fairly new to php and i have no idea how to pass this array back to the page after it has been updated. I've tried searching the internet but i can't find an answer, which i take to mean it's not an obvious one. So is there a way for me to pass these arrays on? Can i post them, or is there a better way for me to do it? I don't want to add them onto the url as there will be a lot of data to pass through.

Link to post
Share on other sites

First of all, is this a Flash game, or is it coded into the PHP?Second of all, if the users input their scores into the form, they most likely won't be accurate, will they?Third of all, if it is an html form, then just make the <form action="yourpage.php" method="POST"> and then access it with the $_POST variable on the next page.And why do you have it stored in an array? if you are already submitting it to a PHP page, just do what you need to do there.Also, as Silver said, your code would really help you get more responsive answers.

Link to post
Share on other sites

You can send the array to the next page, but it won't save the scores or let more then one person see them. For that you need a database. This would only work if you have 1 game going on that is being updated by 1 person, like if you have a family game and one of you is keeping score online. But you would need to output each element of the array as a hidden input element, and then the following page would be able to read it from post.

<form action="scores.php" method="post"><?phpforeach ($scores1 as $score){  echo "<input type=\"hidden\" name=\"scores1[]\" value=\"{$score}\">";}foreach ($scores2 as $score){  echo "<input type=\"hidden\" name=\"scores2[]\" value=\"{$score}\">";}?>

But again, this only works for 1 person at a time, and if the browser gets closed or they go to another site it will be lost.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...