I have a code like this

<? php
if ($type == 1)		//book
			echo $information_array[0]. '. <i><a href="updatebook.php?q=$information_array[1]">'. $information_array[1] . '</a></i>. '. $information_array[2] . ": " . $information_array[3]. ".<br/>";

In the next page

$title= $_GET['q'];
  echo $title;

when I echo $title, I get $information_array[1] as output. But not the value stored in $information_array[1]. Value to $informatino_array[1] is brought from database in the first page using select statement.

5 Years
Discussion Span
Last Post by andarivaadu1
echo "{$information_array[0]}<i><a href=\"updatebook.php?q={$information_array[1]}\">{$information_array[1]}</a></i>{$information_array[2]}: {$information_array[3]}<br/>";

Can you please give me the explanation for the above code, why is your code working and not mine.


Variables within single quotes are taken to be literals - so you'll display the variable name not the variable value. Double quotes are different - they should give you the value when you enclose a variable within them. HOWEVER - if you use array item variables, you have to enclose them in braces {}, so that php can read them as such.
So, anything like this $var or $hello[4] or $_POST has to be placed within braces. You could concatenate strings and variables with the '.' dot, but this makes it very messy (IMO) and I believe it's a bit slower.


The above technique is working for me. But when I echo the variable $title in the next web-page, I am getting the output as shown below.

Book NameResource id #2

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.