| | |
Trying to Hyperlink Values in PHP Dynamic List - Getting Blank Page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
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:
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.
Also the the word 'newspost' to what the name of the column which contains the articles news content but keep the quotes around it.
php Syntax (Toggle Plain Text)
$sqlresult=mysql_query("SELECT * FROM `news_posts` WHERE `post_title`='".$_GET['post']."'"); $sqlresult=mysql_fetch_array($sqlresult); echo $sqlresult['newspost'];
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
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:
Nothing big - just had HTML inside the PHP Tags without quotes. Thanks for the help guys!
php Syntax (Toggle Plain Text)
<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!
![]() |
Other Threads in the PHP Forum
- Previous Thread: please help me on creating library system
- Next Thread: Novice at PHP programming + Final year project
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






