I know I did it right but it doesn't display properly-help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

I know I did it right but it doesn't display properly-help!

Post by canadian_angel »

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>My Books and Chapters</title>
</head>
<body>
<?php // Script 7.4 - books.php

// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

// Create the first array.
$phpvqs = array (1 => 'Getting Started', 'Variables', 'HTML Forms and PHP', 'Using Numbers');

// Create the second array.
$phpadv = array (1 => 'Advanced PHP Programming', 'Object-Oriented Programming ', 'Databases', 'Security');

// Create the third array.
$phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL');

// Create the multidimentional array.
$books = array (
'PHP VQS' => $phpvqs,
'PHP Advanced VQP' => $phpadv,
'PHP and MySQL VQP' => $phpmysql
);

// Print out some values.
print "<p>The third chapter of my first book is <i>{$books['PHP VQS'][3]}</i>.</p>";
print "<p>The first chapter of my second book is <i>{$books['PHP Advanced VQP'][1]}</i>.</p>";
print "<p>The fourth chapter of my fourth book is <i>{$books['PHP and MYSQL VQP'][4]}</i>.</p>";

// See what happens with foreach.
foreach ($books as $key => $value) {
print "<p>$key: $value</p>\n;";
}

?>
</body>
</html>
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: I know I did it right but it doesn't display properly-he

Post by JakeJ »

A description of what is not working, error messages, etc. would be very helpful.

You're unlikely to get any help just by posting code with no explanation.
canadian_angel
Forum Commoner
Posts: 31
Joined: Fri Jun 11, 2010 3:13 pm

Re: I know I did it right but it doesn't display properly-he

Post by canadian_angel »

Oops! Sorry!

A book title is supposed to display here when I run the code :
print "<p>The fourth chapter of my fourth book is <i>{$books['PHP and MYSQL VQP'][4]}</i>.</p>";

but it doesn't it looks like this:
The fourth chapter of my fourth book is .

Thanks!
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: I know I did it right but it doesn't display properly-he

Post by flying_circus »

The problem lies here:

Code: Select all

$phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL');

print "<p>The fourth chapter of my fourth book is <i>{$books['PHP and MYSQL VQP'][4]}</i>.</p>"; 
There is no item number 4 in your array.

What happens when you add another item to $phpmysql?

Code: Select all

$phpmysql = array (1 => 'Introduction to PHP', 'Programming with PHP', 'Introduction to SQL and MySQL', 'chapter 4'); 
Post Reply