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

<?php
$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.

Recommended Answers

All 5 Replies

Member Avatar for diafol
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.

Member Avatar for diafol

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

I don't understand what is Resource id #2

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.