Jump to content

Displaying part news one 1 page and full on another


Boxerman

Recommended Posts

Hi,

 

Im a little confused on how to go about setting up a news section.

 

i.e

 

On my homepage i got it displaying

Title:

Postedby:

brief:

 

i would like a read more button...

 

So it will go around index.php?news=$idfullstory (something like that)

 

and on that page it will automatically show the full story etc..

 

Just a bit confused, so can someone break it down or even better point me in the right direction please?

 

Thanks,

J

Thats what i need help with..

 

At the moment my homepage is something a short version...

 

I've made a page called story.php

 

i  want it to be like story.php?id=1

 

and that will grab all the news for id 1

 

and then story.php?id=2

 

will just grab all news for id number 2

 

etc..

Untested, un-proofread BUT it should at the least point you in the right direction...

 

<?PHP
/*  function to return the first N words of a string */
function shorten_string($string, $wordsreturned) {
$retval = $string;
$array = explode(" ", $string);
   if (count($array)<=$wordsreturned) {
	$retval = $string;
}else{
	array_splice($array, $wordsreturned);
	$retval = implode(" ", $array)." ...";
}
return $retval;
}

/* connect to db */
include ('db.php');

/* create query */
$query = "SELECT * FROM table_name ORDER BY date";

/* execute the query */
$result = mysql_query($query);

/* check to see if an article has been selected */
if(!$_GET['article_id']) {
$article_id = 0;
}else{
$article_id = (int) $_GET['article_id'];
}

/* set the number of words for the brief */
$N = 15;
/* loop thru the results */
while($row=mysql_fetch_array($result)) {
$title = $row['title'];
$posted_by = $row['postedby'];
$brief = shorten_string($row['article_content'], $N)
?>
Title: <?PHP echo $title; ?> <br>
Posted By: <?PHP echo $posted_by; ?> <br>
<a href="index.php?article_id=<?PHP echo row['id']; ?>"><?PHP echo $brief']; ?></a>
<?PHP
if($article_id == $row['id']) {
	echo "<br>" . $row['article_content'] . "<hr>";
}else{
	echo "<br>";
}
}

Still confused.. as it is not working :S

 

This is my full site code:

 

<?php include("include/config.inc.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
<title></title>

<script language='javascript' type='text/javascript'>
<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->
</script> 
</head>
<body>

	<div id="header"></div>	
<div id="container">


	<ul id="topmenu">
		<li><a href="index.php">Home index</a></li>
		<li>-</li>
		<li><a href="contact.php">Contact Us</a></li>
		<li>-</li>
		<li><a href="report.php">Report A Error</a></li>

	</ul>

	<div id="menucontent">

		<div id="links">


			<div id="menu">
				<h3>Menu</h3>
				<ul id="linksmenu">
                        <li><a href="index.php">Home</a></li>
                        <li><a href="request.php">Request</a></li>
                        <li><a href="chart.php">Chart</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');"> mini versie </a></li> 
                               
                        
	      </ul>
				<div id="menulast"></div>
			</div>				

			<div id="menu">
				<h3>Media</h3>
				<ul id="linksmenu">
                        <li><a href="music.php">Music</a></li>
                        <li><a href="videos.php">Videos</a></li>
                        <li><a href="http://facebook.com/truvibefm" target="_blank">Facebook</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');">Player</a></li> 
                               
                        
	      </ul>

<div id="menulast"></div>
			</div>

			<div id="menu">
				<h3>Link</h3>
				<ul id="linksmenu">
					<li></li>
					<li></li>
					<li></li>
				</ul>
				<div id="menulast"></div>
			</div>


</div>		
		<div id="rechts">

			<div id="rechtscontent">				
<h2></h2>
				<ul>
<p><?PHP
/*  function to return the first N words of a string */
function shorten_string($string, $wordsreturned) {
$retval = $string;
$array = explode(" ", $string);
   if (count($array)<=$wordsreturned) {
$retval = $string;
}else{
array_splice($array, $wordsreturned);
$retval = implode(" ", $array)." ...";
}
return $retval;
}

/* connect to db */
include ('include/config.inc.php');

/* create query */
$query = "SELECT * FROM news ORDER BY id";

/* execute the query */
$result = mysql_query($query);

/* check to see if an article has been selected */
if(!$_GET['id']) {



$id = 0;
}else{



$id = (int) $_GET['id'];
}

/* set the number of words for the brief */
$N = 15;
/* loop thru the results */
while($row=mysql_fetch_array($result)) {





$title = $row['title'];



$posted_by = $row['postedby'];



$text = shorten_string($row['text'], $N)



?>



Title: <?PHP echo $title; ?> <br>



Posted By: <?PHP echo $posted_by; ?> <br>



<a href="index.php?id=<?PHP echo row['id']; ?>"><?PHP echo row['$text']; ?></a>



<?PHP
if($id == $row['id']) {
echo "<br>" . $row['text'] . "<hr>";
}else{
echo "<br>";
}
}
?>

I guess, it would be good if you can have two files:

1- Main.php : this will show a list of all news in a short version

2- newsDetails.php: this is to show the full version of the selected news

 

Then in the main.php your link should point to newsDetails.php?id={selected_news_id}

 

 

 

Just looked at script and i needed to edit:

 

<a href="index.php?id=<?PHP echo row['id']; ?>"><?PHP echo row['$text']; ?></a>

 

so i fixed that..

 

now it displays and works.

 

if i wanted to link all i would need is to add

<?PHP echo row['id']; ?>

?

Hi,

 

when using this code:

<?php include("include/config.inc.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
<title></title>

<script language='javascript' type='text/javascript'>
<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->
</script> 
</head>
<body>

	<div id="header"></div>	
<div id="container">


	<ul id="topmenu">
		<li><a href="index.php">Home index</a></li>
		<li>-</li>
		<li><a href="contact.php">Contact Us</a></li>
		<li>-</li>
		<li><a href="report.php">Report A Error</a></li>

	</ul>

	<div id="menucontent">

		<div id="links">


			<div id="menu">
				<h3>Menu</h3>
				<ul id="linksmenu">
                        <li><a href="index.php">Home</a></li>
                        <li><a href="request.php">Request</a></li>
                        <li><a href="chart.php">Chart</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');"> mini versie </a></li> 
                               
                        
	      </ul>
				<div id="menulast"></div>
			</div>				

			<div id="menu">
				<h3>Media</h3>
				<ul id="linksmenu">
                        <li><a href="music.php">Music</a></li>
                        <li><a href="videos.php">Videos</a></li>
                        <li><a href="http://facebook.com/truvibefm" target="_blank">Facebook</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');">Player</a></li> 
                               
                        
	      </ul>

<div id="menulast"></div>
			</div>

			<div id="menu">
				<h3>Link</h3>
				<ul id="linksmenu">
					<li></li>
					<li></li>
					<li></li>
				</ul>
				<div id="menulast"></div>
			</div>


</div>		
		<div id="rechts">

			<div id="rechtscontent">				
<h2></h2>
				<ul>
<p><?PHP
/*  function to return the first N words of a string */
function shorten_string($string, $wordsreturned) {
$retval = $string;
$array = explode(" ", $string);
   if (count($array)<=$wordsreturned) {

$retval = $string;

  }else{
array_splice($array, $wordsreturned);

$retval = implode(" ", $array)." ...";

}
return $retval;
}
/* create query */
$query = "SELECT * FROM news ORDER BY id";

/* execute the query */
$result = mysql_query($query);

/* check to see if an article has been selected */
if(!$_GET['id']) {

$id = 0;
}else{
$id = (int) $_GET['id'];
}
/* set the number of words for the brief */
$N = 15;
/* loop thru the results */
while($row=mysql_fetch_array($result)) {

$title = $row['title'];
$posted_by = $row['postedby'];
$brief = shorten_string($row['text'], $N)
?>
Title: <?PHP echo $title; ?> <br>
Posted By: <?PHP echo $posted_by; ?> <br>
<a href="story.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $brief; ?></a>
<? } ?>

 

When i click link to story.php?id=2 it is displaying all the news not just id=2?

 

Have i done something wrong?

where is this ...

if($id == $row['id']) {
echo "<br>" . $row['text'] . "<hr>";
}else{
echo "<br>";
}

AND because you have NOT included the remainder of your code, we cannot see if have properly closed your div and UL's

That is the full code! promise! it calls header.php which contains most of the coding...

 

and i added that part in which still displaying all

 

<?php include("include/config.inc.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" href="style.css" type="text/css" />
<title></title>

<script language='javascript' type='text/javascript'>
<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->
</script> 
</head>
<body>

	<div id="header"></div>	
<div id="container">


	<ul id="topmenu">
		<li><a href="index.php">Home index</a></li>
		<li>-</li>
		<li><a href="contact.php">Contact Us</a></li>
		<li>-</li>
		<li><a href="report.php">Report A Error</a></li>

	</ul>

	<div id="menucontent">

		<div id="links">


			<div id="menu">
				<h3>Menu</h3>
				<ul id="linksmenu">
                        <li><a href="index.php">Home</a></li>
                        <li><a href="request.php">Request</a></li>
                        <li><a href="chart.php">Chart</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');"> mini versie </a></li> 
                               
                        
	      </ul>
				<div id="menulast"></div>
			</div>				

			<div id="menu">
				<h3>Media</h3>
				<ul id="linksmenu">
                        <li><a href="music.php">Music</a></li>
                        <li><a href="videos.php">Videos</a></li>
                        <li><a href="http://facebook.com/truvibefm" target="_blank">Facebook</a></li>
                        <li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');">Player</a></li> 
                               
                        
	      </ul>

<div id="menulast"></div>
			</div>

			<div id="menu">
				<h3>Link</h3>
				<ul id="linksmenu">
					<li></li>
					<li></li>
					<li></li>
				</ul>
				<div id="menulast"></div>
			</div>


</div>		
		<div id="rechts">

			<div id="rechtscontent">				
<h2></h2>
				<ul>
<p><?PHP
/*  function to return the first N words of a string */
function shorten_string($string, $wordsreturned) {
$retval = $string;
$array = explode(" ", $string);
   if (count($array)<=$wordsreturned) {

$retval = $string;

  }else{
array_splice($array, $wordsreturned);

$retval = implode(" ", $array)." ...";

}
return $retval;
}
/* create query */
$query = "SELECT * FROM news ORDER BY id";

/* execute the query */
$result = mysql_query($query);

/* check to see if an article has been selected */
if(!$_GET['id']) {

$id = 0;
}else{
$id = (int) $_GET['id'];
}
/* set the number of words for the brief */
$N = 15;
/* loop thru the results */
while($row=mysql_fetch_array($result)) {

$title = $row['title'];
$posted_by = $row['postedby'];
$brief = shorten_string($row['text'], $N)
?>
Title: <?PHP echo $title; ?> <br>
Posted By: <?PHP echo $posted_by; ?> <br>
<a href="story.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $brief; ?></a>
<?PHP

if($article_id == $row['id']) {
echo "<br>" . $row['text'] . "<hr>";

}else{

echo "<br>";

}
}
?>

I made a few changes, copy and paste this in its entirety...

<?php 
include("include/config.inc.php"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<title></title>
<script language='javascript' type='text/javascript'>
<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->
</script> 
</head>
<body>
<div id="header"></div>
<div id="container">
<ul id="topmenu">
	<li><a href="index.php">Home index</a></li>
	<li>-</li>
	<li><a href="contact.php">Contact Us</a></li>
	<li>-</li>
	<li><a href="report.php">Report A Error</a></li>
</ul>
<div id="menucontent">
	<div id="links">
		<div id="menu">
			<h3>Menu</h3>
			<ul id="linksmenu">
				<li><a href="index.php">Home</a></li>
				<li><a href="request.php">Request</a></li>
				<li><a href="chart.php">Chart</a></li>
				<li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');"> mini versie </a></li> 
			</ul>
			<div id="menulast"></div>
		</div>
		<div id="menu">
			<h3>Media</h3>
			<ul id="linksmenu">
				<li><a href="music.php">Music</a></li>
				<li><a href="videos.php">Videos</a></li>
				<li><a href="http://facebook.com/truvibefm" target="_blank">Facebook</a></li>
				<li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');">Player</a></li> 
			</ul>
			<div id="menulast"></div>
		</div>
		<div id="menu">
			<h3>Link</h3>
			<ul id="linksmenu">
				<li></li>
				<li></li>
				<li></li>
			</ul>
			<div id="menulast"></div>
		</div>
	</div>
	<div id="rechts">
		<div id="rechtscontent">
			<p>
			<?PHP
			/*  function to return the first N words of a string */
			function shorten_string($string, $wordsreturned) {
				$retval = $string;
				$array = explode(" ", $string);
				if (count($array)<=$wordsreturned) {
					$retval = $string;
				}else{
					array_splice($array, $wordsreturned);
					$retval = implode(" ", $array)." ...";
				}
				return $retval;
			}
			/* create query */
			$query = "SELECT * FROM news ORDER BY id";
			/* execute the query */
			$result = mysql_query($query);
			/* check to see if an article has been selected */
			if(!$_GET['id']) {
				$id = 0;
			}else{
				$id = (int) $_GET['id'];
			}
			/* set the number of words for the brief */
			$N = 15;
			/* loop thru the results */
			while($row=mysql_fetch_array($result)) {
				$title = $row['title'];
				$posted_by = $row['postedby'];
				$brief = shorten_string($row['text'], $N);
				?>
				Title: <?PHP echo $title; ?> <br>
				Posted By: <?PHP echo $posted_by; ?> <br>
				<a href="story.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $brief; ?></a>
				<?PHP
				if($id == $row['id']) {
					echo "<br>" . $row['text'] . "<hr>";
				}else{
					echo "<br>";
				}
			}
			?>
		</div>
	</div>
</div>
</div>
</body>
</html>

<?php 
include("include/config.inc.php"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<title></title>
<script language='javascript' type='text/javascript'>
<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();}
// -->
</script> 
</head>
<body>
<div id="header"></div>
<div id="container">



<ul id="topmenu">





<li><a href="index.php">Home index</a></li>





<li>-</li>





<li><a href="contact.php">Contact Us</a></li>





<li>-</li>





<li><a href="report.php">Report A Error</a></li>



</ul>



<div id="menucontent">





<div id="links">







<div id="menu">









<h3>Menu</h3>









<ul id="linksmenu">











<li><a href="index.php">Home</a></li>











<li><a href="request.php">Request</a></li>











<li><a href="chart.php">Chart</a></li>











<li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');"> mini versie </a></li> 









</ul>









<div id="menulast"></div>







</div>







<div id="menu">









<h3>Media</h3>









<ul id="linksmenu">











<li><a href="music.php">Music</a></li>











<li><a href="videos.php">Videos</a></li>











<li><a href="http://facebook.com/truvibefm" target="_blank">Facebook</a></li>











<li><a href="javascript:NewWindow('miniversie.php','miniversie','250','320','custom','front');">Player</a></li> 









</ul>









<div id="menulast"></div>







</div>







<div id="menu">









<h3>Link</h3>









<ul id="linksmenu">











<li></li>











<li></li>











<li></li>









</ul>









<div id="menulast"></div>







</div>





</div>





<div id="rechts">







<div id="rechtscontent">









<p>









<?PHP









/*  function to return the first N words of a string */









function shorten_string($string, $wordsreturned) {











$retval = $string;











$array = explode(" ", $string);











if (count($array)<=$wordsreturned) {













$retval = $string;











}else{













array_splice($array, $wordsreturned);













$retval = implode(" ", $array)." ...";











}











return $retval;









}









/* create query */









$query = "SELECT * FROM news ORDER BY id";









/* execute the query */









$result = mysql_query($query);









/* check to see if an article has been selected */









if(!$_GET['id']) {











$id = 0;









}else{











$id = (int) $_GET['id'];









}









/* set the number of words for the brief */









$N = 15;









/* loop thru the results */









while($row=mysql_fetch_array($result)) {











$title = $row['title'];











$posted_by = $row['postedby'];











$brief = shorten_string($row['text'], $N);











?>











Title: <?PHP echo $title; ?> <br>











Posted By: <?PHP echo $posted_by; ?> <br>











<a href="story.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $brief; ?></a>











<?PHP











if($id == $row['id']) {













echo "<br>" . $row['text'] . "<hr>";











}else{













echo "<br>";











}









}









?>







</div>





</div>



</div>
</div>
</body>
</html>

 

There ya go dude.

So I am clear as to what is happening...

when you first load the page (making sure that cache has been cleared  and that $_GET['id'] is NOT 'lurking' in memory), all briefs are shown as links BUT 90 is shown in its entirety?

When i go to story.php it displays all the news i.e:

 

Title:123

PostedBy:123

Brief:123

Read More

----

Title:456

PostedBy:456

Brief:456

Read More

----

 

when i click read more on ANY of the storys it just it will just be like this:

 

Title:123

PostedBy:123

Story: sdjaskdjaksdjaksdjkasdjkasjdkasjdkjaskdjaksjd asdohya osdih aosdh aoisdh aoisdh oaisdh oasidhasd

Read More

----

Title:456

PostedBy:456

Brief:456

Read More

 

AS you can see it still displaying other news.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.