Page 1 of 1

Browser Title=Data Result?

Posted: Tue Sep 27, 2005 7:37 pm
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>

Posted: Tue Sep 27, 2005 7:46 pm
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>');

Posted: Tue Sep 27, 2005 8:38 pm
by blacksnday
yea.. the array looks horrible cause of the design code.

Thanks for the help, its works great :)