Page 1 of 1

PHP Problem

Posted: Fri May 22, 2009 8:36 pm
by xldenis
Hello, to all of you experienced PHP developers this may sound like a stupid bug(I started a few weeks ago), but i have been trying to use a php script in a html file. When i used the include command it didn't work, the php ran but didn't do anything. So i changed it to a .php, still it didn't do anything. It runs until the while($row = mysql_fetch_object($result)) at that point the code doesn't seem to do anything any more. The thing is i know that the code works because i have another file list.php that has that exact code and it works there, so please explain what is going on if you can. :) Thanks!


Code: Select all

<!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"><!-- InstanceBegin template="/Templates/Main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Xalu Studios Home Page</title>
<!-- InstanceEndEditable -->
<link href="CSS/style_css.css" rel="stylesheet" type="text/css"/>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>
<div style="background-color:#FFF">
  <div class="header">
<img src="images/logo.jpg" />
</div>
<div class="nav_bar">
<strong>. </strong> <a href="index.html">Home</a><strong>. </strong> <a href="games/games.html">Games</a><strong>. </strong> <a href="about/about.html">About</a><strong>. </strong> <a href="portfolio/portfolio.html">Portfolio</a> <strong>. </strong> <a href="contact/contact.html">Contact</a>
</div>
<!-- InstanceBeginEditable name="left_column" -->
<div class="left_column">
  <ul>
    <li><a href="about/about.html">About</a></li>
    <li> <a href="contact/contact.html">Contact</a></li>
    <li><a href="#">Email</a></li>
  </ul>
</div>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="right_column" -->
<div class="right_column"> 
<h1>Welcome to my Site!</h1>
    <p>hello </p>
 
 
<p>&nbsp;</p>
    <p>Enjoy,</p>
    <p>-X</p>
  <ul>
   <?php
// includes
include("PHPcode/config.php");
include("PHPcode/functions.php");
 
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
 
// select database
mysql_select_db($db) or die ("Unable to select database!");
 
// generate and execute query
$id = mysql_escape_string($_GET['id']);
$query = "SELECT id, slug, timestamp FROM news ORDER BY timestamp DESC LIMIT 0, 5";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
 
// get resultset as object
$row = mysql_fetch_object($result);
 
if (mysql_num_rows($result) > 0)
{
    
    // iterate through resultset
    // print article titles
    while($row = mysql_fetch_object($result))
    {
    
 
?>
 
    <center>
        <li><font size="-1"><b><a href="PHPcode/user/story.php?id=<? echo $row->id; ?>"><? echo $row->slug; ?></a></b></font> </li>
        <br>
        <font size="-2"><? echo formatDate($row->timestamp); ?></font>
        
      </center>
<?
    }
}
else
{
?>
    <p>
    <font size="-1">That press release could not be located in our database.</font>
<?
}
 
// close database connection
mysql_close($connection);
?>
</ul>
</div>
 
<!-- InstanceEndEditable -->
<div class="footer">
<div class="footer_left">
</div>
  <div class="footer_right">
 
  </div>
  </div>
  <div class="footer_mid">
  Design by: <a href="http://XaluStudios.com">Xalu Studios</a> | &copy; <a href="http://XaluStudios.com">Xalu Studios</a> 2009
  
  </div>
</div>
    
</body>
<!-- InstanceEnd --></html>
 

Re: PHP Problem

Posted: Fri May 22, 2009 8:44 pm
by Scriptor
delete line 55.

Re: PHP Problem

Posted: Fri May 22, 2009 8:52 pm
by xldenis
yeah! :D Thanks it works now! :D I told u it was a stupid error!

Re: PHP Problem

Posted: Fri May 22, 2009 8:52 pm
by Scriptor
happens to the best of us =)

Re: PHP Problem

Posted: Fri May 22, 2009 10:06 pm
by xldenis
Hmm, now for some reason it has broken itself, i don't know what has happened to it but it won't display the $row->content?

Re: PHP Problem

Posted: Fri May 22, 2009 10:19 pm
by xldenis
Again, stupid problem, i was fetching bad data..