Hi, this is probably very easy for someone, I have a link that I am creating dynamically. There is no problem if I use a static link but when I try to make it dynamic, I get syntax errors. I am not really a php developer. If someone could help I would appreciate it. Code below:

echo '<li>'."<a href='p1/?ID="$_GET['ID']"&page="$value"'>".$value.'</a>'.'</li>';

Not sure where to put single/double quotes or if they are needed at all. Trying to use a url variable as part of the link. But as soon as I put the $_GET in, that's where I get the syntax error.

thank you for your time.

try this, let me know if theres an error

echo '<li><a href="p1/?ID='.$_GET['ID'].'&page='.$value.'">'.$value.'</a></li>';
commented: yes +5
commented: Thank you very much, this worked perfect. +1

How php string works??
In php you can give single quote or double quote for defining string.
If you start with single quote, php will find next single quote for completion of it.In middle you can also use double quote.
Dot(.) is used for two string concatenation.
Same for double quote. If you want to use double quote inside two double quote you can use back slash.
e.g.

'Hi I" am '.'php developer' => valid
'Hi I" am '."php developer" => valid
'Hi I' am '."php developer" => Not valid
'Hi I\' am '."php developer" => valid
'Hi I am '."<a href="http://php.net">php</a> developer" => Not valid
'Hi I am '."<a href=\"http://php.net\">php</a> developer" => Valid

Even if you are using dream-weaver like editor proper string always give red color.
If something is messy, based on color highlighting you can recognize it.

commented: good examples +9
commented: Thank you so much +1

try this, let me know if theres an error

echo '<li><a href="p1/?ID='.$_GET['ID'].'&page='.$value.'">'.$value.'</a></li>';

This worked perfect, I knew that you concatenated strings using dot syntax, but I am still a little confused why I had to in this string. Is it because the the $_GET function required single quotes in the brackets?

These type syntax issues tend to hold me up.

How php string works??
In php you can give single quote or double quote for defining string.
If you start with single quote, php will find next single quote for completion of it.In middle you can also use double quote.
Dot(.) is used for two string concatenation.
Same for double quote. If you want to use double quote inside two double quote you can use back slash.
e.g.

'Hi I" am '.'php developer' => valid
'Hi I" am '."php developer" => valid
'Hi I' am '."php developer" => Not valid
'Hi I\' am '."php developer" => valid
'Hi I am '."<a href="http://php.net">php</a> developer" => Not valid
'Hi I am '."<a href=\"http://php.net\">php</a> developer" => Valid

Even if you are using dream-weaver like editor proper string always give red color.
If something is messy, based on color highlighting you can recognize it.

Thank you for your reply. Yes, dreamweaver was helping but not giving a solution. I knew about the dot syntax but still a little confused why I had to use it here. Why wouldn't that process as one long string, because of the single quotes inside the $_GET function?

Thank you again.

Member Avatar for diafol

Syntax Prpblems

Ha ha ha. Very funny :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.