Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

If the id doesn't exist how to redirect to id=1?

General discussions related to php

Moderators: macek, egami, gesf

If the id doesn't exist how to redirect to id=1?

Postby dioartis » Thu Aug 09, 2012 10:09 am

I made a "next button" and it displays the following pages even though such id does not exist

Next button
echo "<a href='catalog2.php?id=" . ++$id . "'><h3>Next >>></h3></a>";

Display image on page

$id = $_GET['id'];

$query = mysql_query("SELECT * FROM demotivators WHERE id = '$id' LIMIT 1") or die(mysql_error());



$row = mysql_fetch_object($query);


echo $row->image1 . "
";
dioartis
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Aug 09, 2012 10:07 am

Re: If the id doesn't exist how to redirect to id=1?

Postby dioartis » Thu Aug 09, 2012 10:11 am

http://www.demotivator.im/catalog.php?id=58
after id=58 nothing to display
dioartis
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Aug 09, 2012 10:07 am

Re: If the id doesn't exist how to redirect to id=1?

Postby TomCornar » Sun Sep 16, 2012 11:21 pm

SELECT COUNT(*) as count FROM demotivators WHERE id = '$id'

$count=mysql_fetch_assoc($result);
$count=$count['count'];
If($count >0)
{
/*Your functionality*/
}
else
{
/* redirect */
}
hope this helps.
Regards,
Tom Cornar
Trinay Technology Solutions
http://www.trinay.com
User avatar
TomCornar
New php-forum User
New php-forum User
 
Posts: 25
Joined: Fri Sep 14, 2012 12:06 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron