Reputation: 63
this is my news.php ... This code will show the title, and some news contents. When you click the title, it must get the ID and directs you the article. But mine was not getting the ID.
<?php
include 'connect.php';
?>
<?php
$qry = (mysql_query("SELECT * FROM articles"));?>
<newslist title="Latest News">
<?php
while($row=mysql_fetch_array($qry))
{ ?>
<news category="green" url="asdf.php?id="<?php echo $row['id']?>"" date="<?php echo $row['date']?>">
<headline><?php echo "<h1>".$row['title']."</h1>";?></headline>
<detail><?php echo "<p>".substr($row['content'],0,60)."..."."</p>"; ?> </detail>
</news>
<?php
}?>
</newslist>
This is the javascript code fragment that(i guess) was processing the URL code above. Was the problem exists in the javascript code? (vscroller.js)
var url = $(this).attr('url');
var htext = $(this).find('headline').text();
description.append($('<h1/>').html("<a href='" + url + "'>" + htext + "</a>"));
This is my asdf.php. This is the destination when you click one article.
`<?php
$qry=mysql_query("SELECT * FROM articles");
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
?>
<div id="content">
<?php
while($row=mysql_fetch_array($qry))
{
?>
<p class="head">Posted In: <?php echo $row['category'];?></p>
<div class="line"></div>
<h1><?php echo $row['title'];?></h1>
<div class="line"></div>
<p class="meta"><?php echo $row['date']." "."Written By: ".$row['author'];?>
</p>
<div id="article" class="article">
<p class="intro">
<?php echo "<img src=".$row['image']."/>"."<p>".$row['content']."</p>";?></p>
<div class="line"></div><br /><br />
<?php
}
?>
<p id="pc_reference" class="meta"><a href="demo.php">Back to News Page</a></p>
</div>`
this code is from the page where i display the news.php(main.php)
`<script type="text/javascript">
$(document).ready(function () {
$('#vscroller').vscroller({ newsfeed: 'news.php' });
});
</script>
<html>
<body>
<div class="news-wrapper" id="vscroller"></div>`
the original source for this can be found at http://www.egrappler.com/xml-driven-vertical-news-scroller-script-using-html-and-jquery-vscroller/
Upvotes: 1
Views: 17963
Reputation: 2113
<?php include 'connect.php';?>
<?php
$query = mysql_query("SELECT * FROM articles") or die(mysql_error());
while($row = mysql_fetch_assoc($query)){
$a[] = $row;
foreach($a as $key=>$value){
$array[$key] = $value;
}
}
?>
<?php foreach($array as $a):?>
<news category="green" url="asdf.php?id="<?php echo $a['id']?>"" date="<?php echo $a['date']?>">
<headline><?php echo "<h1>".$a['title']."</h1>";?></headline>
<detail><?php echo "<p>".substr($a['content'],0,60)."..."."</p>"; ?> </detail>
</news>
<?php endforeach;?>
I have rearrange the array so it will print much better.
Upvotes: 1
Reputation: 1155
As you say you have verified the ID column exists, the next step in my opinion would be to
check that this snippet echo $row['id']
is returning the expected data.
Once you have confirmed that, please output an example HTML code source if it is still wrong.
As paulsm4 says we need to see the HTML output so we can help debug what/where the issue is.
Upvotes: 1
Reputation: 2113
First thing you have to make sure that you really have a row named id in your database.
Try this code:
$query = mysql_query("SELECT * FROM articles");
$row = mysql_fetch_array($query));
print_r($row);
So you can verify the fields
Upvotes: 1