Jump to content

cdmafra

Recommended Posts

Hello!

 

I need to create a dynamic page title and description to my website. However, the content is all generated from "index.php" page (example: the URL of post is [...].net/?id=2 ). So, title and description are the same in all pages, the website only has a "real" php file.

 

So, how can I change the title with this situation? I have a mysql table for news and another for news/posts.

 

 

Content generator PHP lines:

 

  <!-- Header -->
    <?php
  if (isset($_REQUEST["id"]))
    {
      $query = "SELECT * FROM news WHERE news_id=".$_REQUEST["id"]."";
      $result = mysql_query($query);
      $row = mysql_fetch_array($result);
  ?>
<div class="twelve columns">
  <div class="row"><h3 class="n3"><?php echo $row["news_title"]; ?></h3>
  </div>
</div>
<div class="row"><!-- Row interior-->
<div class="twelve columns">
<div class="panel">
<p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT</p>
<p><?php echo $row["news_post"]; ?></p>
Link to comment
Share on other sites

Well you didn't provide us with how you are doing your title tags now, so this is a bit of a guess on that for your situation.

<!-- Header -->
    <?php
  if (isset($_REQUEST["id"]))
    {
      $query = "SELECT * FROM news WHERE news_id=".$_REQUEST["id"]."";
      $result = mysql_query($query);
      $row = mysql_fetch_array($result);
  ?>
<!DOCTYPE HTML>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title><?php echo htmlentities($row['news_title']); ?></title>
<meta name="description" content="<?php echo htmlentities($row['news_description']); ?>"/> // You need to chang the news_description to something that your db actually holds to describe the news article.
</head>
</body>
<div class="twelve columns">
  <div class="row"><h3 class="n3"><?php echo $row["news_title"]; ?></h3>
  </div>
</div>
<div class="row"><!-- Row interior-->
<div class="twelve columns">
<div class="panel">
<p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT</p>
<p><?php echo $row["news_post"]; ?></p>
</body>
Link to comment
Share on other sites

  • 3 weeks later...

To do that you'll have to get the news article title before you output the <title></title> tags.

Just like in fastsol example? If yes, this is not working for me ... sorry all mess, but I am a beginner in PHP/MySQL..

 

My base code:

 <title>Motor Racing News | Informações de Altas Rotações</title>


(...)


<?php 
if (isset($_REQUEST["guid"]))
{
    $guid = mysql_real_escape_string($_REQUEST["guid"]); // sanitize the guid 
    $query = "SELECT * FROM news WHERE news_guid='".$guid."'"; 
    $result = mysql_query($query); $row = mysql_fetch_array($result); ?>
    
<div class="twelve columns">
  <div class="row"><h3 class="n3"><?php echo $row["news_title"]; ?></h3>
  </div>
</div>
<div class="row"><!-- Row interior-->
<div class="twelve columns">
<div class="panel">
<p id="data"><?php echo $row["news_date"]; ?>, <?php echo$row["hour"] ;?> GMT</p>
<p><?php echo $row["news_post"]; ?></p
>
Edited by cdmafra
Link to comment
Share on other sites

 

Just like in fastsol example? If yes, this is not working for me ... sorry all mess, but I am a beginner in PHP/MySQL..

 

 

As Ch0cu3r suggested, the MySQL query needs to be executed prior to displaying the <title> tag. In the code shown above, the query appears to be after the page title.

Link to comment
Share on other sites

I haven't worked with Comet either, but it's basically just establishing and maintaining a connection while waiting for the server to push responses to you, rather than pulling the data from the server with Ajax (though both work).

JavaScript works on all browsers, so this should work, and you're not sending any confident data, so it's fine.

JavaScript function for that...

function setTitle(title){ document.title = title; return null; }
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.