Jump to content

Recommended Posts

So I have this code working fine and it shows almost everything I need.

 

But I want the "bizname" to show in the title tag.

 

I tired echoing the bizname in the title tag but it doesn't do anything.

Everything else I look for is about making separate header pages but maybe I'm not searching for the right term?

<?php 

$dbc = mysqli_connect('localhost','','','')
	or die ('Error connecting to the database');
$RID = $_GET['bizid'];
	$query="SELECT * FROM business WHERE `bizid` = '$RID'";
	$data=mysqli_query($dbc,$query);
	

	
	if($data->num_rows == 0){
	
	echo 'Sorry, there are no matches';
	}
	else
	{

	echo '<table>';
while ($row = mysqli_fetch_array($data)){

echo '<tr border="1">
		<td class="td1"><h1>' .$row['bizname'] . '</h1></td>';
echo '</tr>';

echo '<tr>
		<td class="td3">' .$row['bizhours'] . '</td>';
echo '</tr>';


		echo 	'<tr><td class="td2">' .$row['bizdescription'] .'</td>';

echo '</tr>';

echo '<tr>
		<td class="td2">' .$row['bizaddress'] . '</td>';
echo '</tr>';


echo '<tr>
		<td class="td2">Phone: ' .$row['bizphone'] . '</td>';
echo '</tr>';

echo '<tr>
		<td class="td2">Fax: ' .$row['bizfax'] . '</td>';
echo '</tr>';


echo '<tr>
		<td class="td2">Email: ' .$row['bizemail'] . '</td>';
echo '</tr>';



echo 	'<tr><td></td>';

echo '</tr>';



}
echo '</table>';

}

mysqli_close($dbc);















?>

Link to comment
https://forums.phpfreaks.com/topic/280391-get-record-name-into-title/
Share on other sites

the page title is defined in the html header.  If you want to change it you need to write out the whole page, including the header, when you are displaying the results of the query - so

else{
$row = mysql_fetch_assoc($data);
$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>
{$row['bizname']}
</title>
</head>
<body>
<table>
<tr border="1">
<td class="td1"><h1>{$row['bizname']}</h1></td>
</tr>
<tr>
<td class="td3">{$row['bizhours']}</td>
</tr>
<tr>
<td class="td2">{$row['bizdescription']}</td>
</tr>
<tr>
<td class="td2">{$row['bizaddress']}</td>
</tr>
<tr>
<td class="td2">Phone : {$row['bizphone']}</td>
</tr>
<tr>
<td class="td2">Fax : {$row['bizfax']}</td>
</tr>
<tr>
<td class="td2>Email : {$row['bizemail']}</td>
</tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
HTML;
echo $html;

You can't loop multiple results, as you can only have 1 title per page.

Edited by Muddy_Funster

you can't - as far as I am aware - change the header with PHP once it's been set without rendering the entyre page again.  You could maybe get away with calling

header('Title: '.$row['bizname']);
But that's untested and I would say unlikely as well.

 

The way PHP works it that it is processed on the server before any information is displayed in the browser, this meens that all PHP code on a page is run through before a single element is shown on the screen (unless you use something like output buffers), to change things after the page has been "drawn" then you need something client side, like javascript.  You could theoreticly have javascript/jquery change the DOM for the page title - but again, that's not something I have ever played about with.

Cheers muddy

 

So - without sounding like a broken record....(cd to you younger peeps)

 

how then, do such seemingly simple sites get a record name fro mysql (like in my instance, bizname) into the title when parsing from another page? Like, "click here for this cafe", then the cafe name is in the page title..

 

 

I keep thinking I'm missing a trick here somewhere...

you need to rearrange the logic on your page so that the main (business logic) php code is executed first, then you build and output the html document using the data that php produced/retrieved.

 

for the code in post #1 in this thread, that would mean replacing the echo statements with code that concatenates the output into a php variable. you would then simply echo the php variable holding the page title and the php variable holding the main page content at the appropriate points in your html document. all the html document, from the <!DOCTYPE html> tag to the closing </html> tag, would come after the main php code on the page.

 

edit: organizing the logic on your page the way that i have described (i.e. using php as a template engine) also eliminates a common problem like in this thread - http://forums.phpfreaks.com/topic/280490-what-is-wrong-with-the-code/

Edited by mac_gyver
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.