budlust Posted April 4, 2010 Share Posted April 4, 2010 For these scripts I just wanted to get a list of news articles posted on news.php then when you click on the article link, it will take you to article.php?id= ### . I'm just really looking for php critique since this is a template that I did not make. Please don't hesitate to be too harsh, I'm Just trying to improve my php skills. I was also gonna add pagination once I learn more about that to news.php Here is the header. The config just has the db password and stuff. header.php <? include "config.php" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>TITLE!</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" /> <link href="layout.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .iepng, #site-nav a { behavior: url("iepngfix.htc") } </style> </head> <body id="page1"> <div class="tail-top"> <div id="main"> <!-- header --> <div id="header"> <div class="row-1"> <div class="fleft"><a href="index.html"><img alt="" src="images/logo.jpg" /></a></div> <div class="fright"> <form id="search-form" action=""> <div><input type="text" value="Search" class="search-input"/><input type="image" src="images/search-button.gif" /></div> </form> </div> </div> <div class="row-2"> <ul id="top-menu"> <li><a href="index.php">link</a></li> <li><a href="link.php">link</a></li> <li><a href="link.php">link</a></li> <li><a href="link.php">link</a></li> <li><a href="link.php">link</a></li> <li><a href="link.php">link</a></li> <li><a href="link.php">link</a></li> </ul> </div> </div> <div id="content"> <div class="wrapper"> This is the contents of the web page. As you can see i have the include/get_news.php which retreives the news articles from the db. I know this isnt the best way to go about this but im trying to figure out how to implement it without the include. The footer just has links and copyright info. news.php <? include "include/header.php" ?> <? include "include/menu_left_main.php" ?> <div id="right-side"> <div class="box3"> <div class="border-right"> <div class="border-bot"> <div class="border-left"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="left-bot-corner"> <div class="inner"> <div class="box5"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="inner"> <h3>News</h3> <ul class="list3"> <? include "include/get_news.php" ?> </ul> <div class="wrapper"> <div class="extra-link"> <em class="left"><em class="right"><a href="#">News Archive</a></em></em> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <? include "include/footer.php" ?> And this is the script that gets the news article info and posts it into news.php get_news.php <? $query = "SELECT * from news"; $result = $db->query($query); $num_results = $result->num_rows; for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc(); echo '<li><img alt="" src="images/2page-img1.jpg" class="fleft" />'; echo '<h4><a href="article.php?id='; echo $row["ID"]; echo '">'; echo $row["TITLE"] ; echo '</a></h4>'; echo $row["CONTENTS"]; echo '</li>'; } $result->free(); $db->close(); ?> Quote Link to comment Share on other sites More sharing options...
xX_SuperCrazy_Xx Posted April 4, 2010 Share Posted April 4, 2010 Hi there, you should always escape output before you display it in the HTML page. This can be done using the function htmlspecialchars Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.