Jump to content

Recommended Posts

I am teaching myself PHP using the Visual Quickstart book on PHP6 and MySQL 5. I'm on chapter 2, and I can't for the life of me get my script to work right. I'm not getting an error message - it's just not formatting the results as it's supposed to. Here's the URL to the page I did:

 

http://mdh-test.com/php_training/sorting.php

 

 

Here's the code:

 

<!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=UTF-8" />

<title>sorting arrays</title>

</head>

 

<body>

 

<table border="2" cellspacing="3" cellpadding="3" align="center">

<tr>

<td><h2>Rating</h2></td>

<td><h2>Title</h2></td>

</tr>

</table>

 

<?php # Script 2.8 - sorting.php

$movies = array (

10 => 'Casablanca',

9 => 'To Kill a Mockingbird',

2 => 'The English Patient',

8 => 'Stranger Than Fiction',

5 => 'Story of the Weeping Camel',

7 => 'Donnie Darko'

);

 

echo '<tr><td colspan="2"><b>In their original order:</b></td></tr>';

 

foreach ($movies as $key => $value) {

echo "<tr><td>$key</td>

  <td>$value</td></tr>\n";

}

 

?>

</body>

</html>

 

The values are not going into the TDs. I've checked this on FF3 on the Mac and on IE7 on my WinXP emulator, and nada.

 

Can anyone please help? What have I done wrong? It seems like such a basic script that I don't think the problem is that my hosting is still on PHP5, not 6.

 

Thank you in advance for your help.

Link to comment
https://forums.phpfreaks.com/topic/138565-what-am-i-doing-wrong/
Share on other sites

You are closing the tble too early. Put the </table> after the php and before the </body>

 

Viewing the source of the page would have yielded the problem.

 

Thank you. I can see where I went wrong. I did view the source, as posted below, but I couldn't see the forest for the trees. Such a basic script. Such an simple mistake. I, BTW, know better. <slapping self upside the head> I'm not a n00b at HTML, fer dang sake!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.