Browser Title=Data Result?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Browser Title=Data Result?

Post by blacksnday »

I have been trying to figure out how to get the <title></title>
to reflect stuff thats pulled from the mysql database and displayed on page.

I figured the <title> needs a variable, but how do you get a variable to get and pass info
to the <title>from a random item shown on page from a database result?

Example of a data result and what I would like to get shown on <title></title>

Code: Select all

function show_last_five_entries($url) { 
$bash = 1;
$max_results = 10; 
$from = (($bash * $max_results) - $max_results); 
$sql = mysql_query("SELECT * FROM news ORDER BY date DESC LIMIT $from, $max_results"); 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM news"),0); 
$total_bashs = ceil($total_results / $max_results); 
$newsbox1 = "<div id=showindexnewsrowtwo class=bordright>"; 
$newsbox2 = "<div id=showindexnewsrowone>";
$row_count = 0;
while ($row = mysql_fetch_assoc($sql)) 
  { 
	  	$row_color = ($row_count % 2) ? $newsbox1 : $newsbox2;
        echo "<tr><td>$row_color";
	    $bash = $row['id']; 
	    /* get number of comments */
	    $comment_query = "SELECT count(*) FROM comments WHERE newsid='$bash'";
        $comment_result = mysql_query ($comment_query);
        $comment_row = mysql_fetch_row($comment_result); 
    $newposts = array ( "<div id=showindexnewstitle><a href=$url/comment/bash/$bash>" => $row['lova'], "</a></div>Submitted By" => $row['name'], "<br /><a href=$url/comment/bash/$bash>$comment_row[0] Comments</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=$url/tell/bash/$bash>Tell-A-Friend</a><br /><br />" => $row['news'] ); 
    foreach ( $newposts as $postfield => $postinput ) 
    { 
      $postinput = submitTags($postinput, 1, 1); 
      echo "<b>{$postfield}</b>  {$postinput}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; 
    } 
    echo "<br><br></td></tr></div></div>"; 
      $row_count++; 
   }  
}
The above is my code to display the last 10 entries, but will work as an example
of how to grab the News Title and display the text of it on the Browser Title

Where the following is what grabs the Title Info then links it to the comment page, this would be
what I want to get the <title></title> to show.

Code: Select all

$newposts = array ( "<div id=showindexnewstitle><a href=$url/comment/bash/$bash>" => $row['lova'], "</a></div>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

$newposts is a really screwed up array...

Anyway, you're really confusing me here. All I got was that you wanted to show something inside the <title> tag.

Code: Select all

echo '<title>Your Site - '.$title_extra.'</title>';
So if you wanted that last 10 $row['lova'] entries to show...

Code: Select all

$title_extra = '';
while ($row = mysql_fetch_assoc($sql)) {
  $title_extra .= $row['lova'] . ' ';
}
print('<title>Your Site - '.$title_extra.'</title>');
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post by blacksnday »

yea.. the array looks horrible cause of the design code.

Thanks for the help, its works great :)
Post Reply