0

I have news pages generated dynamically using page news.php taking data that is input into a MySql table and would like to have the page title to be the same as the news headline of each page.

I'm searching internet and although there is lots of info on this subject I'm still not having any success, so I'm looking for some help on where I'm going wrong. (must add that I'm a novice).

I have raed that it is possible using the following code:

<title><?php echo $pageTitle; ?></title>

and then have the following on a page to be included:

$pageTitle = "My page title";

What I'm looking for is the correct code to go into the include page to replace "My Page Title" that will dynamically give the news headline.

I'm hoping that someone can help me to extract the code I need from the following code in news.php that dynamically creates individual pages for each news item:

<?php
@include_once("class/Configure.php");
if(!$c_Connection->Connect())
{
	@header("Location:message.php?msg=2");
	exit();
}
@include_once("class/ss_news.php");
$c_ss_news = new ss_news($c_Connection);
$news = $_GET["news"];
 $c_ss_news->m_NEW_Id = $news;

?>
<!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" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Supplier Scan - News</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="style/styles.css" rel="stylesheet" type="text/css" media="all" />
<link href="style/addto.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="scripts.js"></script>
</head>
<body>

		<div class="wrapper">
       	  <div class="container">
       	     <?php @include_once("includes/header.php"); ?>
                        <div class="contentWrapper">
                            <div class="contentWrapper_leftCol">
                                <div class="contentinner_bg_col">
                                    <div class="contentinner_bg_bottom">
                                      <div class="contentinner_bg_top">
                                        <!--<h3>Latest News </h3>-->
										<?php
										if($resultNews = $c_ss_news->GetNewsById())
										{
											if($rowNews = @mysql_fetch_array($resultNews))
											{
												$newsId = $rowNews["NEW_Id"];
												echo ' <h3>'.$rowNews["NEW_Headline"].'</h3>';
												
												echo '<p><b>'.$rowNews["NEW_Summary"].'</b></p>';
												echo '<p>';
												if($rowNews["NEW_Image"] != "")
												{
													echo '<img src="news/images/'.$rowNews["NEW_Image"].'" title="'.$rowNews["NEW_ImageTitle"].'" alt="'.$rowNews["NEW_ImageTitle"].'" style="float:left; margin-right:10px; " />';
												}
												echo $rowNews["NEW_Desc"].'</p>';
												$resultPost = mysql_query("SELECT DATE_FORMAT('".$rowNews["NEW_Postedon"]."', '%d %b %Y')");
												$posted = @mysql_fetch_array($resultPost);
												$pdf = $rowNews["NEW_PdfName"];
											}
										}//End of if($resultNews = $c_ss_news->GetNewsById())
										
										?>
4
Contributors
12
Replies
23
Views
7 Years
Discussion Span
Last Post by diafol
0

Thanks Ardav, although that doesn't answer my question.

In my news.php I would like to change Line 18 of the code to be dynamic instead of the fixed code that it is. So:

18.  <title>Supplier Scan - News</title> <!--to be changed to--> 18.  <title><?php echo $pageTitle; ?></title>18.  <title>Supplier Scan - News</title>

<!--to be changed to-->

18.  <title><?php echo $pageTitle; ?></title>

That's the easy bit me as a novice can do, what I need is the code that would go into an "includes/page" to deliver $pageTitle.

The code I've given above is from my news.php that creates the dynamic news pages and I'm hoping that someone with greater knowledge than me can help and extract the pieces of code that will do this for me.

I've tried several variations of the code in lines 36-42 and inserting $pageTitle in to the equation and then put that code into the includes/page but unfortunately I'm getting it wrong somewhere.

Any assistance would help me also further my knowledge of php, so I would be very greatful indeed.

0

Like ardav said, you need to set $pageTitle before it can be used. Is it being set in one of the included files before the <title> tag?

0

Thanks for reply Borzoi.

That's correct I agree I need to set the $pageTitle before it can be used and that's the piece of coding that I need, which I will then add to one of the includes pages.

The code that is on lines 36-42 above displays the News Headline on the dynamic pages, I would like to have the News Headline (NEW_Headline) as the dynamic page title i.e. $pageTitle.

Thanks once again for any assistance you can offer.

0

I understand what you mean now.

If $rowNews["NEW_Headline"] is being set in one of the included files before the <title> tag, you could just use that or set $pageTitle using $pageTitle = $rowNews["NEW_Headline"]

0

Yes, that's what I need, so let me give you the code that I used to set the $pageTitle but that was unsuccesful as all I got was a totally blank page.

<?php										if($resultNews = $c_ss_news->GetNewsById())														if($rowNews = @mysql_fetch_array($resultNews))											{											$pageTitle = $rowNews["NEW_Headline"];

?>

So not sure where I'm going wrong, wasn't even sure I was doing teh right thing so hence the big posting above.

0

You haven't closed either of those if statements.

<?php
if($resultNews = $c_ss_news->GetNewsById())
{
  if($rowNews = @mysql_fetch_array($resultNews))
  {
    $pageTitle = $rowNews["NEW_Headline"];
  }
}
?>
0

Thanks for your reply but that is not working as I've added that code to the include page and changed the code for the title, uploaded the pages and now if I try and load one of the dynamic news pages I get a completely blank page.

0

I've played around with this and discovered that if I put the above code from Borzoi into a separate and new "includes" page then it worked.

Thanks for your efforts, most appreciated.

-1

<?php

$result = mysql_query("SELECT db FROM tabelle WHERE id = 1");
$row = mysql_fetch_assoc($result);
?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title><?php echo $row['name']; ?></title> 
0

Please let's not necropost. The above uses deprecated code and does not improve upon the discussion that died 4 years ago.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.