It is currently Fri Mar 29, 2024 8:29 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: PHP gallery script help
PostPosted: Sun Feb 20, 2005 5:38 pm 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Hello everyone.

I ripped off a tutorial script for a picture gallery, and modifed bits and pieces. I can't get this bit to work right though.

Code:
<?

include("config.inc.php");

/********************************************************************/

// initialization
$result_array = array();
$counter = 0;

$cid = (int)($_GET['cid']);
$pid = (int)($_GET['pid']);

// Category Listing

if( empty($cid) && empty($pid) )
{
$number_of_categories_in_row = 4;

$result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id)
      FROM gallery_category as c
      LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id
      GROUP BY c.category_id" );
while( $row = mysql_fetch_array( $result ) )
{

/* Display categories. */

$result_array[] = "<a href='gallery_view.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")";
}
mysql_free_result( $result );   

$result_final = "<tr>\n";

foreach($result_array as $category_link)
{
  if($counter == $number_of_categories_in_row)
  {   
   $counter = 1;
   $result_final .= "\n</tr>\n<tr><td colspan=4>&nbsp;<br>&nbsp;</td></tr>\n<tr>\n";
  }
else
  $counter++;

  /* Display each category and button to delete. */

  $result_final .= "\t<td><font>".$category_link."<br>";
  if($result_array[2] > 0){
  $result_final .= "<form action=gallery_cat_del.php method=post>";
  $result_final .= "<input type=hidden name=catid value=".$result_array[0].">";
  $result_final .= "<input type=submit value=Delete>";
  $result_final .= "</form>";
}
$result_final .= "</td>\n";

}

if($counter)
{
if($number_of_categories_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";
$result_final .= "</tr>";
}
}

// Thumbnail Listing

else if( $cid && empty( $pid ) )
{
$number_of_thumbs_in_row = 5;

$result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" );
$nr = mysql_num_rows( $result );

if( empty( $nr ) )
{
$result_final = "\t<tr><td><font>No Category found</td></tr>\n";
}
else
{
  while( $row = mysql_fetch_array( $result ) )
   {
    $result_array[] = "<a href='gallery_view.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>";
   }
  mysql_free_result( $result );   

  $result_final = "<tr>\n";
   
  foreach($result_array as $thumbnail_link)
  {
   if($counter == $number_of_thumbs_in_row)
   {   
    $counter = 1;
    $result_final .= "\n</tr>\n<tr>\n";
   }
   else
    $counter++;

    $result_final .= "\t<td><font>".$thumbnail_link."</td>\n";
    }
   
if($counter)
         {
if($number_of_photos_in_row-$counter)
$result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";

   $result_final .= "</tr>";
  }
}
}

   // Full Size View of Photo
   else if( $pid )
   {
      $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" );
      list($photo_caption, $photo_filename) = mysql_fetch_array( $result );
      $nr = mysql_num_rows( $result );
      mysql_free_result( $result );   

      if( empty( $nr ) )
      {
         $result_final = "\t<tr><td><font>No Photo found</td></tr>\n";
      }
      else
      {
         $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" );
         list($category_name) = mysql_fetch_array( $result );
         mysql_free_result( $result );   

         $result_final .= "<tr>\n\t<td><font>
                  <a href='gallery_view.php'>Categories</a> &gt;
                  <a href='gallery_view.php?cid=$cid'>$category_name</a></td>\n</tr>\n";

         $result_final .= "<tr>\n\t<td align='center'><font>
               <br />
               <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' />
               <br />
               $photo_caption
                                        <br />
               </td>
               </tr>";
      }
   }


/******************************************/
/* Output page. */

include("includes/pagetop.html");

echo '<br><br><br>';
echo '<center><a href="control.php">Back to Control Panel</a></center>';
echo '<p>';

// Final Output
echo <<<__HTML_END

<center><table width='90%' border='0' align='center'>
$result_final      
</table></center>

__HTML_END;

include("includes/pagebottom.html");

?>

And this is the file it is sent to for the deletion:
Code:
<?

include("config.inc.php");
include("includes/session.php");

if($session->logged_in){
if($session->isAdmin()){
  echo '<center><font>';

// If logged in as admin...

/*************************************************/


function delete_category( $category_id )
{
global $images_dir;
$result = mysql_query( "SELECT photo_filename FROM gallery_photo WHERE photo_category='".addslashes( $category_id )."'" ); 
while( $row = @mysql_fetch_array( $result ))
{
   unlink($images_dir."/".$row[0]);
}
mysql_query( "DELETE FROM gallery_photo WHERE photo_category='".addslashes( $category_id )."'" );
mysql_query( "DELETE FROM gallery_category WHERE category_id='".addslashes( $category_id )."'" );
}

include("includes/pagetop.html");

if(!delete_category($_REQUEST['catid'])){
echo '<font>';
echo '<center>';
echo '<h1>Failure!</h1>';
echo '<p>';
echo '<center>The gallery editing page will reload in a moment.';
echo '<meta http-equiv="refresh" content="1;url=mydomain/gallery_delete.php">';
}
else{
echo '<font>';
echo '<center>';
echo '<h1>Success!</h1>';
echo '<p>';
echo '<center>The gallery editing page will reload in a moment.';
echo '<meta http-equiv="refresh" content="1;url=mydomain/gallery_delete.php">';
}

include("includes/pagebottom.html");

/***************************************************/

}
else{
   echo '<center><font>';
include("includes/pagetop.html");
include("includes/hidden.php");
include("includes/pagebottom.html");
  }
}
else{
  include("includes/pagetop.html");
  include("includes/hidden.php");
  include("includes/pagebottom.html");
}

?>

The part I added for deleting stuff is:
Code:
  /* Display each category and button to delete. */

  $result_final .= "\t<td><font>".$category_link."<br>";
  if($result_array[2] > 0){
  $result_final .= "<form action=gallery_cat_del.php method=post>";
  $result_final .= "<input type=hidden name=catid value=".$result_array[0].">";
  $result_final .= "<input type=submit value=Delete>";
  $result_final .= "</form>";


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 7:40 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Ah, I'll just re-write it entirely.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 7:45 am 
NO! I'm not a flooder!
NO! I'm not a flooder!

Joined: Mon Feb 21, 2005 7:01 am
Posts: 172
Location: Bulgaria, Pazardjik
Adam wrote:
Ah, I'll just re-write it entirely.


or better, use CPG or Coppermine


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 8:14 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
Open source = every feature you'll never need.

The downside of such things is all the extra crap that I simply don't want.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 8:35 am 
Experienced
Experienced

Joined: Sun Feb 20, 2005 3:11 pm
Posts: 92
Location: Australia
I should add, yes, much open source stuff is very nice. But it is so often bloated with crap. That's why I prefer doing it myself.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
100WebSpace © 2011