Only my include file or other content showing

 I just started working  with php and I can't understand why my code isn't working, I want  my nav to display across but it displays up and down, and my content(or whatever you wanna call it) only displays when I'm not include(ing) nav.php. 

index.php
[php]

<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'blog'; mysql_select_db($dbname) or die; $sql = mysql_query( "SELECT * FROM content ORDER BY id"); while ($row = mysql_fetch_assoc($sql)) { $id = $row['id']; $author = $row['author']; $title = $row['title']; $date = $row['date']; $content = $row['content']; $time = $row['time']; include('nav.php'); echo "

$row[title]



By:

$row[author]



$row[date] @ $row[time]


$row[content]

";} ?> [/php]

nav.php

[php]

<?php $sql = mysql_query( "SELECT * FROM nav ORDER BY linkn"); while ($row = mysql_fetch_assoc($sql)) { $link = $row['link']; echo "

$row[link]

";} ?>

[/php]

Hi Matt,

Remember that you’ve already used variables $sql and $row in index.php file. Normally, re-declaring them can get you in trouble. So, try to rename $sql and $row variables in your nav.php file…like:

[php]<?php
$sql1 = mysql_query( “SELECT * FROM nav ORDER BY linkn”);
while ($row1 = mysql_fetch_assoc($sql1))
{

$link = $row1[‘link’];
?>[/php]

Also, this portion:
[php]echo “

$row[link]

“;}[/php]
should be:
[php]echo “

”.$row1[‘link’] .”

”;}[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service