Jump to content

Theres probably a simple solution to this...


sectachrome

Recommended Posts

Hey guys,

 

Im building a news site for a class.  One page has all the news stories listed, each of which links to their respective stories in their entirety.  I have the main news page working, but I cannot get the information to pass on to the story page from the links.

 

Main news page

<?php
include ("connect.php");
$query = "SELECT * FROM News";

$result = mysql_query($query);
if(!$result)
{
die("Could not query the database:<br />". mysql_error());
}
?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BusinessLink</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
</div>
<div id="bodymain">
	<div id="menu">
		<ul>
			<li>Home</li>
			<li>|</li>
			<li>Jobs</li>
			<li>|</li>
			<li>Calendar</li>
		</ul>
	</div>

	<div id="hometext">
		<h2>News</h2>
		<?php
		while($row = mysql_fetch_assoc($result))
		{
		?>	
		<div id="newsbox">
		<p><h1><?php echo $row["Title"];?></h1></p>
			<p><?php echo $row["Date"];?>, <?php echo $row["Author"];?></p>
			<p><?php echo $row["Blurb"];?></p>
			<p><a href="story.php?which=<?php echo $row["ID"];?>">Read More</a> </p>
		</div>
		<?php } ?>

	</div>

	<div id="homenewscol">

	</div>
</div>
</div>
</body>
</html>
<?php
mysql_close($connection);
?>

 

Story details page

<?php
include("connect.php");
$iID = $_GET["which"];
$query = "SELECT * FROM News WHERE ID = $iID";

$result = mysql_query($query);
if(!$result)
{
die("Could not query the database:<br />". mysql_error());
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BusinessLink</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
</div>
<div id="bodymain">
	<div id="menu">
		<ul>
			<li><a href="index.php">Home</a></li>
			<li>|</li>
			<li><a href="news.php">News</a></li>
			<li>|</li>
			<li><a href="jobs.php">Jobs</a></li>
			<li>|</li>
			<li><a href="calendar.php">Calendar</a></li>
		</ul>
	</div>

	<div id="hometext">
		<p><h1><?php echo $row["Date"];?></h1></p>
      		<p><a href="news.php">Back To News</a> </p>

	</div>

	<div id="homenewscol">
	<h2>Top Stories</h2>
	</div>
</div>
</div>
</body>
</html>
<?php
mysql_close($connection);
?>

 

Everything seems right to me and it is passing on the ID to the story page but nothing will show up  ???  I want the story to come up in the "hometext" div.

 

Thanks in advance!

Link to comment
Share on other sites

Yeah, Ive tried putting it elsewhere on the page and still get nothing.  The database works, everything comes up on the main news page.  And I do have a row called ID.

 

When I mouse over the "Read more" links on the main news page you can see its picking up the ID in the link, and the correct ID also shows in the URL of the story detail page.

 

Sorry, Im not too good at the technical jargon.

Link to comment
Share on other sites

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BusinessLink</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="container">
<div id="header">
</div>
<div id="bodymain">
	<div id="menu">
		<ul>
			<li><a href="index.php">Home</a></li>
			<li>|</li>
			<li><a href="news.php">News</a></li>
			<li>|</li>
			<li><a href="jobs.php">Jobs</a></li>
			<li>|</li>
			<li><a href="calendar.php">Calendar</a></li>
		</ul>
	</div>

	while($row=mysql_fetch_array($result)) {
                                 echo "<div id=\"hometext\"><p><h1>".$row["Date"]."</h1></p>"
                                 echo "<p><a href="news.php">Back To News</a> </p></div>";
	}
	<div id="homenewscol">
	<h2>Top Stories</h2>
	</div>
</div>
</div>
</body>
</html>
<?php
mysql_close($connection);
?>

Link to comment
Share on other sites

while($row=mysql_fetch_array($result)) {
   echo "<div id=\"hometext\">
<p><h1>".$row["Date"]."</h1></p>"
   echo "<p><a href="news.php">Back To News</a> </p></div>";

//and for any other divs with content from database

}

 

AH! Right you are.  D'oh!

 

Thanks a lot man.  You saved me another 30 mins of staring at the screen in bewilderment.  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.