database help

  • Creatore Discussione Creatore Discussione bonzer1
  • Data di inizio Data di inizio

bonzer1

Nuovo Utente
18 Mag 2006
17
0
1
www.sluurpy.it
Ciao ho una pagina in php del genere
PHP:
<?php
//zOOm Media Gallery//
/** 
-----------------------------------------------------------------------
|  zOOm Media Gallery! by Mike de Boer - a multi-gallery component    |
-----------------------------------------------------------------------

-----------------------------------------------------------------------
|                                                                     |
| Author: Mike de Boer, <http://www.mikedeboer.nl>                    |
| Copyright: copyright (C) 2006 by Mike de Boer                       |
| Description: zOOm Media Gallery, a multi-gallery component for      |
|              Joomla!. It's the most feature-rich gallery component  |
|              for Joomla!! For documentation and a detailed list     |
|              of features, check the zOOm homepage:                  |
|              http://www.zoomfactory.org                             |
| License: GPL                                                        |
| Filename: special.php                                               |
|                                                                     |
-----------------------------------------------------------------------
* @version $Id: special.php,v 1.20 2006/08/02 18:52:50 kevinuru Exp $
* @package zOOmGallery
* @author Mike de Boer <[email protected]> 
**/
// MOS Intruder Alerts
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $size;
/**
 There are three special image-display formats:
 0: Top ten viewed images (most hits)
 1: Ten last submitted images (last id's)
 2: Ten last commented images
 4: Top rated
**/
$sorting = intval(trim(mosGetParam($_REQUEST, 'sorting')));
if ($sorting == 1 || $sorting == 2) {
	$where_prefix = "WHERE ";
} else {
    $where_prefix = "AND ";
}
if ($zoom->_isAdmin) {
	$where_clause = "";
} else {
    $where_clause = $where_prefix."cats.catpassword = '' AND img.published = 1";

}
switch($sorting){
  case 0:
    $database->setQuery("SELECT DISTINCT img.imgid AS id, img.catid AS gallery_id FROM #__zoomfiles AS img LEFT JOIN #__zoom AS cats ON img.catid = cats.catid WHERE imghits > 0 $where_clause ORDER BY imghits DESC LIMIT 10");
    break;

  case 1:
    $database->setQuery("SELECT DISTINCT img.imgid AS id, img.catid AS gallery_id FROM #__zoomfiles AS img LEFT JOIN #__zoom AS cats ON img.catid = cats.catid $where_clause ORDER BY id DESC LIMIT 10");
    break;

  case 2:
    $database->setQuery("SELECT DISTINCT com.imgid, img.imgid AS id, img.catid AS gallery_id, max(com.cmtid) as maxcmt FROM #__zoomfiles AS img LEFT JOIN #__zoom_comments AS com ON com.imgid = img.imgid LEFT JOIN #__zoom AS cats ON img.catid = cats.catid $where_clause GROUP BY id ORDER BY maxcmt desc LIMIT 10");
    break;
  
  case 4:
    $database->setQuery("SELECT DISTINCT img.imgid AS id, img.catid AS gallery_id, img.votenum, (img.votesum/img.votenum) AS rating FROM #__zoomfiles AS img LEFT JOIN #__zoom AS cats ON img.catid = cats.catid WHERE img.votesum > 0 AND img.votenum > 0 $where_clause ORDER BY rating desc, img.votenum DESC LIMIT 10");
    break;
  
  default:
    die("You must visit this page the legit way, remember?");
}
$zoom->_result = $database->query();
if ($zoom->_CONFIG['ratingOn']) {
    $zoom->createRatingCSS();
}
?>
<script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/components/com_zoom/lib/js/prototype.js"></script>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
  <tr>
    <td width="30" class="<?php echo $zoom->_tabclass[1]; ?>"></td>
    <td class="<?php echo $zoom->_tabclass[1]; ?>">
	<?php if ($zoom->_CONFIG['mainscreen']) { ?>
		<a href="<?php echo sefRelToAbs("index".$backend.".php?option=com_zoom&Itemid=".$Itemid);?>">
		<img src="<?php echo $mosConfig_live_site;?>/components/com_zoom/www/images/home.gif" alt="" border="0" />&nbsp;&nbsp;<?php echo _ZOOM_MAINSCREEN;?></a>&nbsp;|&nbsp;
	<?php 
	}
    if($sorting==0) echo _ZOOM_TOPTEN;
    else if($sorting==1) echo _ZOOM_LASTSUBM;
    else if($sorting==2) echo _ZOOM_LASTCOMM;
    else if($sorting==4) echo _ZOOM_TOPRATED;
    ?>
    </td>
  </tr>
</table>
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<?php
$i = 0;
$imgcnt = 0;
$tabcnt = 0;
if (mysql_num_rows($zoom->_result) > 0) {
	while($row = mysql_fetch_object($zoom->_result)){
		$imgcnt++;
		$zoom->setGallery($row->gallery_id);
		$zoom->_counter = 0;
		foreach($zoom->_gallery->_images as $image){
			if($image->_id == $row->id){
				$i = $zoom->_counter;
			}
			$zoom->_counter++;
		}
		$zoom->_gallery->_images[$i]->getInfo();
		if ($zoom->_gallery->isMember() && $zoom->_gallery->_images[$i]->isMember()) {
			echo '<tr class="'.$zoom->_tabclass[$tabcnt].'"><td width="20">&nbsp; '.$imgcnt.' &nbsp;</td>';
			if (!$zoom->_CONFIG['popUpImages']) {
				?>
				<td align="left" width="<?php echo $zoom->_CONFIG['size'];?>">
				<a href="<?php echo sefRelToAbs("index".$backend.".php?option=com_zoom&amp;Itemid=".$Itemid."&amp;page=view&amp;catid=".$zoom->_gallery->_id."&amp;key=".$i."&amp;hit=1");?>">
				<?php
			} else {
				$params = $zoom->encrypt("catid=".$zoom->_gallery->_id."&amp;key=".$i."&amp;isAdmin=".$zoom->_isAdmin."&amp;hit=1");
				?>
				<td align="left" width="<?php echo $zoom->_CONFIG['size'];?>">
				<?php
				$link = "<a href=\"javascript:void(0)\" onClick=\"window.open('".$mosConfig_live_site."/components/com_zoom/www/view.php?popup=1&amp;q=".$params."', 'win1', 'width=";
				if ($size[0] < 550) {
					$link .= "550";
				} elseif ($size[0] > $zoom->_CONFIG['maxsize']) {
					$link .= $zoom->_CONFIG['maxsize'] + 50;
				} else {
					$link .= $size[0] + 40;
				}
				$link .= ", height=";
				if ($size[1] < 550) {
					$link .= "550";
				} elseif ($size[1] > $zoom->_CONFIG['maxsize']) {
					$link .= $zoom->_CONFIG['maxsize'] + 50;
				} else {
					$link .= $size[1] + 100;
				}
				$link .= ", scrollbars=1').focus()\">\n";
				echo $link;
			}
			echo '<img src="'.$zoom->_gallery->_images[$i]->_thumbnail.'" border="0" alt="" /></a></td><td width="10"></td>';
			echo '<td align="left"><b>'.$zoom->_gallery->_images[$i]->_filename.'</b><br />';
			if ($zoom->_CONFIG['showHits'])
				echo _ZOOM_HITS.' = '.$zoom->_gallery->_images[$i]->_hits.'<br />';
			if ($zoom->_CONFIG['ratingOn']) {
				echo $zoom->_gallery->_images[$i]->getStars();
			}
			echo "<a href=\"".sefRelToAbs("index.php?option=com_zoom&Itemid=".$Itemid."&catid=".$zoom->_gallery->_id)."\">".$zoom->_gallery->getCatVirtPath()."</a>";
			//new feature
			if ($sorting == 2){ 
				$dir_prefix = $mosConfig_live_site."/components/com_zoom/www/";
				$smilies = $zoom->_getSmiliesTable();
				$lastelement = count($zoom->_gallery->_images[$i]->_comments);
				
				if ($lastelement <> ""){
					$comment = $zoom->_gallery->_images[$i]->_comments[$lastelement-1];
	
					echo "<table style=\"border: 1px solid #cccccc\" width=\"98% \">";
					echo "<tr><td><b>".$comment->_name."(".$comment->_date.")</b></td></tr>";
					$theComment = $comment->_processSmilies($comment->_comment,$dir_prefix,$smilies);
					
					echo "<tr><td>".$theComment."</td></tr>";
					echo "</table>";
				}
			}
			echo "</td></tr>";
			if ($tabcnt >= 1) {
				$tabcnt = 0;
			} else {
				$tabcnt++;
			}
		} else {
		?>
				<tr>
		<td><?php echo _ZOOM_NOIMG; ?></td>
	</tr>
	<?php
		}
	}
} else {
	?>
	<tr>
		<td><?php echo _ZOOM_NOIMG; ?></td>
	</tr>
	<?php
}
?>
</table>

che mi estra dal database le immagini piu votate, le piu cliccate e le piu commentate, però io vorrei che facesse tutto cio ma me le estraesse da una precisa categoria (che so divertenti, paesaggi . . . ) e non le piu votate, cliccate . . . in generale

come posso fare ?

queste sono le categorie del mio database jos_zoom


Grazie :(
Codice:
 Testo completo  	  catid   	  catname   	  catdescr   	  catdir   	  catimg   	  catpassword   	  catkeywords   	  subcat_id   	  pos   	  hideMsg   	  shared   	  published   	  uid   	  catmembers   	  custom_order

e jos_zoomfiles
Codice:
 Testo completo  	  imgid   	  imgname   	  imgfilename   	  imgdescr   	  imgkeywords   	  imgdate   	  imghits   	  votenum   	  votesum   	  published   	  catid   	  uid   	  imgmembers
 

Discussioni simili