PHP Re-direct

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
iant
Forum Newbie
Posts: 4
Joined: Sun Aug 09, 2009 5:59 am

PHP Re-direct

Post by iant »

Hello,

I have been building a website with some PHP coding but im stuck on one bit!!
I want the script to automatically open the hyperlink without the visitor clicking on the link... (similar to browser re-direct)

It currently displays the match result and then invites the visitor to click in order to view the match report, I just want the match report to display instantly without having to click.

I have been tring everything but no joy.

Could you help (save me from going mad) :banghead:

Thanks
Ian

Code: Select all

 
<?php
 
$host = 'localhost';
$user = '****';
$password = '****';
$txt_db_name = '****';
 
$connection = mysql_connect("$host","$user","$password")
or die(mysql_error());
mysql_select_db("$txt_db_name",$connection)
or die(mysql_error());
 
$pref = mysql_query(" 
SELECT TeamName AS teamname 
FROM tplss_preferences 
WHERE ID = '0' 
", $connection) 
or die(mysql_error()); 
 
$teamname = mysql_fetch_array($pref); 
 
mysql_free_result($pref); 
 
$get_report = mysql_query(" 
SELECT 
M.MatchID AS id, 
MT.MatchTypeName AS typename, 
O.OpponentName AS opp, 
M.MatchPlaceID AS place, 
M.MatchGoals AS gf, 
M.MatchGoalsOpponent AS ga, 
DATE_FORMAT(M.MatchDateTime, '%W %d %b') AS time 
FROM tplss_matches M, tplss_matchtypes MT, tplss_opponents O 
WHERE M.MatchDateTime < CURRENT_TIMESTAMP AND M.MatchReport != '' AND 
MT.MatchTypeID = M.MatchTypeID AND
O.OpponentID = M.MatchOpponent
ORDER BY M.MatchDateTime DESC 
LIMIT 1", $connection) 
or die(mysql_error()); 
 
$data = mysql_fetch_array($get_report); 
 
//Check if it's home or away game 
if($data['place'] == 1) 
{ 
echo" 
$data[time]<br> 
$data[typename]<br> 
$teamname[teamname] $data[gf] - $data[opp] $data[ga]<br> 
<a href=\"matchdetails.php?id=$data[id]\"target=\"_self\">match report</a>"; 
} 
elseif($data['place'] == 2) 
{ 
echo" 
$data[time]<br> 
$data[typename]<br> 
$data[opp] $data[ga] - $teamname[teamname] $data[gf]<br>
<a href=\"matchdetails.php?id=$data[id]\"target=\"_self\">match report</a>"; 
} 
 
mysql_free_result($get_report);
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: PHP Re-direct

Post by ben.artiss »

Hi iant,

Do you mean using the header() function? If that's what you mean you can leave the script and go to a different URL using e.g:

Code: Select all

header("Location: index.php"); exit;
Hope that helps.

Regards,

Ben
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: PHP Re-direct

Post by ben.artiss »

I forgot to mention actually, if you've already started to output any HTML you won't be able to redirect without using the ob_start() at the very beginning of your file and ob_end_flush() at the very end. Good luck anyway! :)
iant
Forum Newbie
Posts: 4
Joined: Sun Aug 09, 2009 5:59 am

Re: PHP Re-direct

Post by iant »

Hi Ben,

Thanks for your reply

The header() would not work on this, because the URL is made up of code that is pulled from the MySql

Code: Select all

<a href=\"matchdetails.php?id=$data[id]\"target=\"_self\">match report</a>";
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: PHP Re-direct

Post by ben.artiss »

Hi again,

Unless I'm not seeing something would it not be possible to just do:

Code: Select all

header("Location: matchdetails.php?id=$data[id]"); exit;
But like I said, if you've already started to output HTML without using output buffering then it will give you an error I think.

Good luck!
Post Reply