Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2013, 12:49 PM   PM User | #1
luxuri
New to the CF scene

 
Join Date: Oct 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
luxuri is an unknown quantity at this point
PHP Titles?

Hi all,

I have a page, where named example.php?id=5 then the code will retrieve the rows from id 5, which then the rest of the code puts them out. For example, id 5 may be the person John and then id 4 may be Jane.

The mysql retrieving works when i try to display the info. However, is it possible to use these to set my <title></title>?
I've tried many ways,
PHP Code:
<?php echo htmlspecialchars($retrieverowENT_QUOTES'utf-8');?>
where $retrieverow was set at the bottom of the page(someone told me so) and others like $_GET. However, the title still remained blank.

Is there a solution to this? Many thanks
luxuri is offline   Reply With Quote
Old 02-18-2013, 02:19 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Did you put it between your <title> elements?
You can do this of course. It simply means restructuring so your processing ends up before your HTML output. Ultimately this is what you should do in PHP anyways.
A really simple example:
PHP Code:
<?php

// Do whatever to get these records.  I'll just pretend that I have a function for it.
$record fetchMaRecord($_GET['id']);
// now $record has what it need, and presumably only one result.
?>
<Doctype. . .>
<html>
    <head>
        <title><?php echo $record['name'];?></title>
    </head>
    <body>
....
Simple as that. Just make sure that you don't output the head and title until after you've retrieved your results.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-19-2013, 04:47 AM   PM User | #3
luxuri
New to the CF scene

 
Join Date: Oct 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
luxuri is an unknown quantity at this point
Hi

Yes, I have put it between <title>. However, it still doesn't work.
I've tried something similar to your suggestions before. However, nothing still appears. Does it matter of I am using PDO to connect to the database?
luxuri is offline   Reply With Quote
Old 02-19-2013, 01:37 PM   PM User | #4
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 585
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
can you post what you have now?
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is online now   Reply With Quote
Old 02-20-2013, 02:17 PM   PM User | #5
luxuri
New to the CF scene

 
Join Date: Oct 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
luxuri is an unknown quantity at this point
Hi Arcticwarrio and Fou-Lu,

Thanks a bunch for attempting to help, but I've solved it myself by simply moving this
PHP Code:
foreach ($sql as $row
statement at the top of the page, and everything worked.

Many thanks!
luxuri is offline   Reply With Quote
Old 02-21-2013, 01:51 PM   PM User | #6
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 585
Thanks: 15
Thanked 65 Times in 65 Posts
Arcticwarrio is on a distinguished road
if you find the first row from each query missing you can reset it without a new query too:

PHP Code:

db
('open'); 
$Results query("SELECT * FROM table");
db('close');

while (
$Row mysql_fetch_array($Results)) {

//script

}

mysql_data_seek($Results0); // resets the query back to the first row

while ($Row mysql_fetch_array($Results)) {

//another script


__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:24 PM.


Advertisement
Log in to turn off these ads.