Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

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

Codes here !

Moderators: macek, egami, gesf

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

Postby dioartis » Thu Aug 09, 2012 10:27 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 . "
";

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 Nullsig » Thu Aug 09, 2012 12:31 pm

SELECT * FROM demotivators WHERE id IN ('$id',1) ORDER BY id DESC LIMIT 1
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI


Return to mySQL & php coding

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.