Jump to content

Did I do this right? Different adult ratings change results.


djfox

Recommended Posts

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
}
}
?>

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 ?>

<?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.

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

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?

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.