943,645 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2007
  • PHP RSS
Sep 6th, 2008
0

Trying to Hyperlink Values in PHP Dynamic List - Getting Blank Page

Expand Post »
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);
?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dizdain is offline Offline
3 posts
since Sep 2008
Sep 7th, 2008
0

Re: Trying to Hyperlink Values in PHP Dynamic List - Getting Blank Page

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.
php Syntax (Toggle Plain Text)
  1. $sqlresult=mysql_query("SELECT * FROM `news_posts` WHERE `post_title`='".$_GET['post']."'");
  2. $sqlresult=mysql_fetch_array($sqlresult);
  3. 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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 7th, 2008
0

Re: Trying to Hyperlink Values in PHP Dynamic List - Getting Blank Page

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:

php Syntax (Toggle Plain Text)
  1. <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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dizdain is offline Offline
3 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: please help me on creating library system
Next Thread in PHP Forum Timeline: Novice at PHP programming + Final year project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC