Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 07-31-2006, 02:57 PM   #1 (permalink)
Blumengruss
Recruit
 
Join Date: Jul 2006
Location: Philadelphia, Pennsylvania
Posts: 6
Blumengruss is on a distinguished road
Send a message via Skype™ to Blumengruss
Question Can't Get a Variable to Increment after a Post

This is my first post ever on a PHP forum. It's great to feel like there might be some help for my fried brain.

I am working on a site that includes a weekly calendar that will be connected to a database. The script I've written includes a function so that when the weekly calendar loads, it always starts with the last Monday. This is working.

I wrote the script also intending that the visitor can scroll forward or back to another week. This is done by means of a variable called "$scroll". If $scroll = 2, for example, the week that that is displayed is 2 weeks in the future. This is working, too.

I know it sounds dumb, but I can't get the value of $scroll to increment after the visitor slects from a menu how many weeks they want to scroll ahead and then hits the submit button. The value of $scroll goes to whatever is selected, but it never increments. It's like it gets reset to 0 each time there is a post.

I think these are the relevant parts of my code:


$increment=$_POST['increment'];
$scroll=$scroll+$increment;

(code displaying the calendar table...)

<form action="reservations.php" method=post>
Scroll Forward by
<select name="increment">
<option value="1">1 Week</option>
<option value="2">2 Weeks</option>
<option value="3">3 Weeks</option>
<option value="4">4 Weeks</option>
</select>
<input type="submit" name="scroll_forward" value="Go">
</form>


I hope I've explained enough for someone to help.

Many thanks in advance.
Blumengruss is offline   Reply With Quote
Old 07-31-2006, 05:08 PM   #2 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Are you storing the value of $scroll in a session variable, or is it included in the uri query?
__________________
Current Project
Redline is offline   Reply With Quote
Old 07-31-2006, 05:41 PM   #3 (permalink)
Blumengruss
Recruit
 
Join Date: Jul 2006
Location: Philadelphia, Pennsylvania
Posts: 6
Blumengruss is on a distinguished road
Send a message via Skype™ to Blumengruss
Hi. Thanks for your reply.

I don't know much about what session variables are, but I don't think I'm using them. I'm just setting those variables I listed to the $_POST value.
Blumengruss is offline   Reply With Quote
Old 07-31-2006, 07:44 PM   #4 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Well, if you want to keep using $_POST vars, you'll need to set the $scroll variable as a hidden post var

PHP Code:
<?php
// set scroll equal to scroll + increment
$scroll $_POST['scroll'] + $_POST['increment'];
?>
(code displaying the calendar table...)

<form action="reservations.php" method=post>
Scroll Forward by
<select name="increment">
<option value="1">1 Week</option>
<option value="2">2 Weeks</option>
<option value="3">3 Weeks</option>
<option value="4">4 Weeks</option>
</select>
<input type="hidden" name="scroll" value="<?=$scroll>">
<input type="submit" name="scroll_forward" value="Go">
</form>
__________________
Current Project
Redline is offline   Reply With Quote
Old 08-01-2006, 08:40 AM   #5 (permalink)
Blumengruss
Recruit
 
Join Date: Jul 2006
Location: Philadelphia, Pennsylvania
Posts: 6
Blumengruss is on a distinguished road
Send a message via Skype™ to Blumengruss
Hi Redline,

Thank you for your follow-up and helpful tips. I tried what you suggested* and it works.

I've also looked into session variables, and can imagine that these would be useful for the intention I have. Would session variables be a better or more "correct" way to do this?

Many thanks,
Eric

*I had to add a ? in one place, so that the hidden input value is:

"<?=$scroll?>" rather than
"<?=$scroll>"

I took a shot in the dark about that, and I don't actually understand that syntax. At first I thought they were opening and closing php tags. Are they? Because when I tried "<?php=$scroll?>" it did not work.
Blumengruss is offline   Reply With Quote
Old 08-01-2006, 11:36 AM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
Quote:
"<?=$scroll?>"
is short form of php script. if you wanted to use the longer form, it would be:
PHP Code:
<?php =$scroll?>
or
PHP Code:
<?php echo "$scroll";?>
Notice the space fromphp to "=".

In your case I would suggest session variables, since I guess you don't want the visitor to snoop on your code, and find out how you increment your scroll value.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 08-01-2006, 03:04 PM   #7 (permalink)
Blumengruss
Recruit
 
Join Date: Jul 2006
Location: Philadelphia, Pennsylvania
Posts: 6
Blumengruss is on a distinguished road
Send a message via Skype™ to Blumengruss
Hi redhead,

Thanks so much for for your thoughts on the session variables and also for explaining the tag syntax to me. I've done a bit of eye-rubbing on this and I have to admit that no matter how many times I type it in, I always get a parse error (unexpected "=") when I set the input value this way:

PHP Code:
value=<?php =$scroll?>
or
PHP Code:
value="<?php =$scroll?>"
But it works the other two ways you mention:

PHP Code:
value=<?php echo "$scroll";?>
and
PHP Code:
value="<?=$scroll?>"
and it also works this way:

PHP Code:
value="<?php echo $scroll;?>"
Maybe it's the version of PHP that's running on my host server?

Anyway, your answer and the others I've gotten here have been more than enough to get me going.

Tak skal du have
Blumengruss is offline   Reply With Quote
Old 08-01-2006, 09:53 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i don't think that <?php =$scroll?> is valid either.
__________________
Mike
sde is offline   Reply With Quote
Old 08-02-2006, 07:29 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
Quote:
Tak skal du have
You're welcome, no matter where you are, it still remains a small world
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TIP #3: PRE/POST increment analisys. Valmont Standard C, C++ 5 04-15-2005 11:01 AM
reset Variable in HTML awieds MS Technologies ( ASP, VB, C#, .NET ) 2 04-11-2005 11:32 PM
creating dynamic variable names sde PHP 5 11-02-2002 09:03 AM


All times are GMT -8. The time now is 08:19 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting