djfox Posted September 13, 2007 Share Posted September 13, 2007 I`m adding in an adult rating to images so people who say they don`t want to see images with adult content won`t see them. But it doesn`t seem to be working. Can someone check me over: <?php $adult = $_SESSION['adult']; if( $adult > 0){ ?> <? $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; ?> <?php } else { if( $adult < 1){ ?> <? $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat, adult=0 ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; ?> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
hostfreak Posted September 13, 2007 Share Posted September 13, 2007 Start by putting the php opening/closing tags in the correct place: <?php $adult = $_SESSION['adult']; if( $adult > 0){ $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; } else { if( $adult < 1){ $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat, adult=0 ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; } } ?> You only need one opening and close tag, in your situation. Also, you were using the short_tags (<? ?>) in some places, which may be disabled. Generally it is always recommend to use: <?php ?> Quote Link to comment Share on other sites More sharing options...
djfox Posted September 13, 2007 Author Share Posted September 13, 2007 <?php $adult = $_SESSION['adult']; if( $adult > 0){ $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; } else { if( $adult < 1){ $cat=isset($_REQUEST['cat'])?$_REQUEST['cat']:-1; if(!$offset) $offset=0; $recent = 0; $res = mysql_query("Select id,url,addDate FROM image WHERE cat=$cat, adult=0 ORDER BY id DESC")or die( mysql_error() ); echo "<table width='100%'>"; while( $row = mysql_fetch_row($res) ){ if( $recent >= $offset && $recent < ($offset + 25 )){ if( $recent%5 == 0 ){ echo "<tr><td><tr><td><tr><td><tr><td><tr>"; } echo "<td align=center><a href='trances.php?id=$row[0]'><img src='thumbnail.php?img=$row[1]' border=0></a>"; } $recent = $recent + 1; } echo "</table>"; } } ?> Ok, did that. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted September 13, 2007 Share Posted September 13, 2007 I don't see where you have <a href="http://www.php.net/session_start">session_start()</a> So putting it together: <?php session_start(); $adult = $_SESSION['adult']; //etc ?> Also, to be sure, you do assign the value of adult to the $_SESSION array, correct? I don't see it happening on this page, but can only assume you do on another page. Edit: Edited out mistake I made Quote Link to comment Share on other sites More sharing options...
djfox Posted September 13, 2007 Author Share Posted September 13, 2007 Yes, those values are defined previously. I just didn`t feel the need to post those parts here since they aren`t the problem. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted September 13, 2007 Share Posted September 13, 2007 Actually, those are quite relevant. If you weren't getting a value to $adult, then it wouldn't work. Your not getting any errors, correct? It's just not working? And by not working, you mean it is showing adult images, no matter the preference? Can you check to see that $adult is getting a value, by echoing it? Quote Link to comment Share on other sites More sharing options...
djfox Posted September 13, 2007 Author Share Posted September 13, 2007 There are no errors. And yes you are right, it is not working as in it is showing the adult images regardless of the preference. Echoing $adult brings back 1. Doing a few runs I`m seeing that the code I set to change the adult rating preference for some reason is not entering the correct information when saving (which I`m not sure why, it`s the same codes I`ve been using through the site). So looks like I have to get that to work first. Thanks for looking into and pulling out a suggestion that led me to see there was a problem elsewhere. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted September 13, 2007 Share Posted September 13, 2007 No problem. If you get that fixed and still have a problem with this, let us know. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.