Solved

How to pass values of a variable to another page

Posted on 2014-01-07
5
371 Views
Last Modified: 2014-01-08
Hi,

I have a calendar whose each date is a clickable button (image1.jpg). The code that I have used for to present each date as a button is mentioned below, which is placed within a while loop so that every date is a displayed.
echo "<td";
if($day==$day_num){
     echo " bgcolor='yellow'"; //highlight TODAY in yellow
     echo "><form action='show.php' method='post'><input type='submit' name='$datetime' value='$day'></form></td>";
}

Open in new window

The variable $datetime consists of the value that is generate by mktime function in PHP. Uptill here everything is fine.

Now when I click a particular date, I want to display the tasks for that date. I want to select the tasks based on the value that is passed by $datetime on another page.

How to achieve it? I hope you got my query. Kindly let me know if you require anymore input from side.

Thanks in advance.
image1.jpg
0
Comment
Question by:Vipin Kumar
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39764058
If you are only passing one value to show.php with each date click, then on show.php you could use this to retrieve the day number.


reset($_POST);
$key = key($_POST); //$key will be the input name ($datetime)
echo $_POST[$key]; //the day number
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39764170
It appears that you might be new to PHP; that is hardly a sin -- we were all new to the language once.  Your question is full of multi-layer issues that require some background in computer science.  Here are some places to start your learning adventures.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

There is information on date/time processing in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

There is information in SQL data base work in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

The most important advice I can offer is, "Don't push yourself!"  It takes time to learn this material.  Choose challenges that are interesting and rewarding and don't be in too much of a hurry.   Build a teaching library from you challenges and solutions.  You'll get there in less time than you think it might take!
0
 
LVL 1

Author Comment

by:Vipin Kumar
ID: 39764206
It appears that you might be new to PHP; that is hardly a sin -- we were all new to the language once.  Your question is full of multi-layer issues that require some background in computer science.
I am not new to PHP, I have read books and learnt about PHP, would say not as much you must have done and you know about the language. But I guess instead of making fun of others I would suggest that you provide help, because education is for sharing but not to keep it to yourself.
My question is not of multi layer questions because I am not using any database as of now within application that I am building. My simple question is how do I pass a button's value to the next page.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39764396
It would much more common and straightforward to put the date in a known variable instead of the name of the submit button.
echo "<td";
if($day==$day_num){
     echo " bgcolor='yellow'"; //highlight TODAY in yellow
     echo "><form action='show.php' method='post'><input type='text' name='thisdate' value='$datetime'><input type='submit' name='submit' value='$day'></form></td>";
}

Open in new window

Then on 'show.php' you can get the value of $_POST['thisdate'] and you will have the $datetime value you put in the original page.  If you need to, you can make it a 'hidden' <input> instead of a 'text' type.
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39764972
Set up the while loop so the output looks like this. No need for a new form tag for every day.
<form action='show.php' method='post'>
<table border="1" cellpadding="6">
<tr>
<td><button name='2014-07-01' value='07'>7</button></td>
<td><button name='2014-08-01' value='08'>8</button></td>
<td><button name='2014-09-01' value='09'>9</button></td>
<td><button name='2014-10-01' value='10'>10</button></td>
</tr>
</table>
</form>

Open in new window

(Convert the datetime to a string if it's not already)
//echo the form tag and table start tags, insert rows as needed
echo "<td";
if($day==$day_num){
     echo " bgcolor='yellow'"; //highlight TODAY in yellow
     echo "><button name='$datetime' value='$day'>$day</button></td></form></td>";
}
//close the table and form

Open in new window

At show.php retrieve the value of the clicked date as I have demonstrated in my first post.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now