Hello. I'm new to the community so hello everyone!

I am having some difficulties with my php script. I am trying to generate a list of the latest 10 news topics in my site and code those topic titles to hyperlink to another page, news.php, which will show the entire article. My problem is that when I visit my page, everything looks good except for my dynamic table is blank - there is no data shown, only the column header. I have highlighted the code I editted to transform the table text into hyperlinks. Forgive me if it's something obvious, I'm relatively new to .php and mysql. Below is the code:

<?php require_once('Connections/users.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_news = 10;
$pageNum_news = 0;
if (isset($_GET['pageNum_news'])) {
  $pageNum_news = $_GET['pageNum_news'];
}
$startRow_news = $pageNum_news * $maxRows_news;

mysql_select_db($database_users, $users);
$query_news = "SELECT post_title FROM news_posts ORDER BY post_date DESC";
$query_limit_news = sprintf("%s LIMIT %d, %d", $query_news, $startRow_news, $maxRows_news);
$news = mysql_query($query_limit_news, $users) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);

if (isset($_GET['totalRows_news'])) {
  $totalRows_news = $_GET['totalRows_news'];
} else {
  $all_news = mysql_query($query_news);
  $totalRows_news = mysql_num_rows($all_news);
}
$totalPages_news = ceil($totalRows_news/$maxRows_news)-1;
?><link href="../includes/Style.css" rel="stylesheet" type="text/css">
<div class="latest_news_box">
  <p>Latest News:<br />
  </p>
  
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td></td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo "<a href='news.php?post=".$row_news['post_title']."'></a>". "<br />"; ?></td>
      </tr>
      <?php } while ($row_news = mysql_fetch_assoc($news)); ?>
  </table>
</div>
<?php
mysql_free_result($news);
?>

Unless the variable is not posted in the url bar when clicking the link, I would say the bug is in a mysql query inside the news.php page. So when you click the link that leads to your (currently) blank article, is the identity/variable in the url bar? If it is then try using something like the code below to retrieve the data when in the news.php page.

$sqlresult=mysql_query("SELECT * FROM `news_posts` WHERE `post_title`='".$_GET['post']."'");
$sqlresult=mysql_fetch_array($sqlresult);
echo $sqlresult['newspost'];

Also the the word 'newspost' to what the name of the column which contains the articles news content but keep the quotes around it.

Well, I figured it out after some detailed analyzing and tinkering. I just had the HTML Tags and PHP Tags misplaced. I changed the highlighted code to the following:

<td><a href="news.php?post=<?php echo $row_news['post_title']?>"><?php echo $row_news['post_title']?></a></td>

Nothing big - just had HTML inside the PHP Tags without quotes. Thanks for the help guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.