Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2004, 12:26 PM
Authorized User
 
Join Date: Aug 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default syntax question

I've got a syntax question that's probably pretty simple.

This is the line of code I was using before.
Code:
if ($POST_['skill_lvl4'] != "none"){
I want to change it so that I can build it into a loop.
Code:
$a = 4;
if ($POST_['skill_lvl$a'] != "none"){
I don't think this is working. How do I work that variable in?

__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
 
Old July 14th, 2004, 04:06 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You need to use double quotes instead of single quotes.

if($_POST["skill_lf$a"] != "none")

By the way, what is $POST_? Isn't it supposed to be $_POST?

HTH,

Snib

<><
 
Old July 14th, 2004, 04:36 PM
Authorized User
 
Join Date: Aug 2003
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default

Thanks! Those syntax issues really get me.

Oh, and the $POST_ was a typo. Sorry about that.

 
Old July 14th, 2004, 07:18 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

The reason this doesn't work is because varaibles aren't replaced in single quoted strings.

Therefore this works:
if ($POST_['skill_lvl'.$a] != 'none'){

Double quotes are also fine for the array.

Single quoted strings are often times more efficient. Though in your case a double quoted array indice would be ok.

The reason that single quotes are more efficient is because the string parsing algorithm is less complicated, variables and special characters aren't replaced in single strings. By special characters I mean the newline character \n, or the tab character \t, or other such characters. These are the literal string when included in a single quoted string instead of a special character. Whereas when included in double quoted strings these are interpretted as special characters and variables are replaced with their respective values.

Because the string parsing algorithm is less complicated, that means less processing power is required, which makes the script more efficient.

http://www.php.net/manual/en/language.types.string.php



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 14th, 2004, 07:40 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

...why is my last post in this message messed up? :-(

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another newb syntax question mean34dean Access VBA 4 April 4th, 2008 07:45 AM
SQL Syntax question ThomasWikman BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 May 7th, 2007 01:25 AM
sql access syntax question using "LIKE" katie456 SQL Server 2000 3 October 10th, 2003 05:49 PM
Syntax question please. savoym VBScript 2 August 12th, 2003 12:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.