ID based navigation from DB?


#1

Hi,

I’m fairly new to PHP. I’ve used it with flash here and there in the past to create updateable flash sites for users but am trying to learn more than just working with it in flash.

I’m trying to create an id based navigation system for my site. What I want it to do is pull information from the database and post it into the php file. But instead of displaying all the posts on one page I want it to split the posts up with the id based navigation type thing…

[php]<?

break;
case “”:

?>[/php]

My problem is I have it written out in my code so it pulls and writes the command like that. It seems to be writing it but not spliting the page up at all and running the command. If you look at the html to the php through the browser it just displays that as a tag in front of every post.

I’ve tried alot of things and can’t seem to get it to work. If you want to see what it’s doing to me check my file out at this link…

http://www.evanbartlett.com/test/index.php

See how it’s just displaying everything on one page still? Wierd. I know the code I’m using is based off of what I learned to make it work with flash. Maybe that could be it. I’ve gotten the same code to work fine if I’m not trying to split it up into the whole id based idea. I don’t know what I’m doing wrong so if you want here’s my code.

[php]<?

switch($action) {
case “”:

?>

this is default <?

// Define database connection details
$dbHost = “localhost”;
$dbUser = “xxxx”;
$dbPass = “xxxx”;
$dbName = “xxxx”;
$table = “news”;

// Attempt to connect to MySQL server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);

// If the connection was unsuccessful…
if (!$link)
{
// Report error and exit
print “Could not connect to server”;
exit;
}

// Attempt to select database. If unsuccessfull…
if (!@mysql_select_db($dbName))
{
// Report error and exit
print “Could not select $dbName database”;
exit;
}

// Build query to fetch news items from database
// Using ‘ORDER BY posted DESC’ to fetch newest items first
$query = “SELECT * FROM news ORDER BY posted DESC”;

// Execute query
$result = @mysql_query($query);

// If query was okay AND we have at least 1 news item…
if ($result && @mysql_num_rows($result) > 0)
{
// Initialise variable to hold news items
$newsText = “”;

// For each news item returned from query...
while($row = mysql_fetch_array($result))
{
    // Format date in 'mm/dd/yy' format
    $posted = strftime("%m/%d/%y", $row['posted']);

    // Add title to output
$newsText .= '<?php ';
$newsText .= 'break; ';
$newsText .= 'case "';
    $newsText .= $posted  . " | " . $row['title'];
$newsText .= '": ?>';
$newsText .= '<font color="#b20404" face="arial" size="1"><b>';
    $newsText .= $posted  . " | " . $row['title'];
    $newsText .= '</b></font><br>';

   // Add news item body with a double linebreak
$newsText .= '<font color="#111111" face="arial" size="1">';
    $newsText .= stripslashes($row['body']);
    $newsText .= '</font><br><br>';

// EMAIL PARSER
$pattern = ‘/(email|EMAIL)=(.*?)[/(EMAIL|email)]/’;
$replace = ‘\3’;
$newsText = preg_replace($pattern, $replace, $newsText);

// URL PARSER
$pattern = ‘/(url|URL)=(.*?)[/(URL|url)]/’;
$replace = ‘\3’;
$newsText = preg_replace($pattern, $replace, $newsText);

// NEWLINE PARSER
$newsText = ereg_replace(“rn”, “
”, $newsText);

}

// Output news items
print $newsText;
}
else
{
// Tell user no news items were found
print “No news items yet”;
}

// Close link to MySQL server
mysql_close($link);

?>

<? break; } ?>[/php]

If someone could please shed me some light on what to do I would greatly appreciate it. Thanks a ton!


#2

Your server is broken.