Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Odczyt z bazy i wyświetlanie na stronie
Forum PHP.pl > Forum > Przedszkole
frok
Mam plik o nazwie sc_potm.php a w nim:

  1. <?php $galclass = new Gallery;
  2.  
  3. $randomid = $galclass->randompic();
  4. if($randomid) echo '<a href="index.php?site=gallery&picID='.$randomid.'"><img src="images/gallery/thumb/'.$randomid.'.jpg" border="0"></a>';
  5. ?>


Plik jest odpowiedzialny za wyświetlanie losowego zdjęcia z galerii. Cały problem polega na tym, że chciałbym aby pod losowym obrazkiem wyświetlał się jego tytuł. Nie mam pojęcia jak to zrobić, nie umiem zbytnio php, ale coś tam potrafie, w tym przypadku poddaje się.

SQL:
  1. CREATE TABLE IF NOT EXISTS `webs_gallery_pictures` (
  2. `picID` int(11) NOT NULL AUTO_INCREMENT,
  3. `galleryID` int(11) NOT NULL,
  4. `name` varchar(255) NOT NULL,
  5. `comment` text NOT NULL,
  6. `views` int(11) NOT NULL DEFAULT '0',
  7. `comments` int(1) NOT NULL DEFAULT '1',
  8. `votes` int(11) NOT NULL,
  9. `points` int(11) NOT NULL,
  10. `rating` int(11) NOT NULL,
  11. PRIMARY KEY (`picID`)
  12. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
  13.  
  14.  
  15.  
  16. INSERT INTO `webs_gallery_pictures` (`picID`, `galleryID`, `name`, `comment`, `views`, `comments`, `votes`, `points`, `rating`) VALUES
  17. (5, 1, 'pies', 'd', 32, 2, 0, 0, 0),
  18. (4, 1, 'labedz', 'sdsd', 169, 2, 0, 0, 0),
  19. (6, 1, 'kon', 'ty', 77, 2, 0, 0, 0);
ayeo
Witam!

Musisz pokazać kod klasy Gallery. Jeśli jest spora to wrzuć na http://snippie.net

Pozdrawiam!
frok
oto kod gallery.php:
http://snippie.net/snip/0fe6f808
ayeo
Witam!

Chodziło mi o kod klasy Gallery....

Pozdrawiam!
frok
Czy to przypadkiem nie jest to:

http://snippie.net/snip/3ee2e9f3

jeżeli nie to, to nie wiem gdzie tego szukać

odświeżam

  1. <?php
  2. /*
  3.  ########################################################################
  4. #                                                                        #
  5. #           Version 4       /                        /   /               #
  6. #          -----------__---/__---__------__----__---/---/-               #
  7. #           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
  8. #          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
  9. #                       Free Content / Management System                 #
  10. #                                   /                                    #
  11. #                                                                        #
  12. #                                                                        #
  13. #   Copyright 2005-2006 by webspell.org                                  #
  14. #                                                                        #
  15. #   visit webSPELL.org, webspell.info to get webSPELL for free           #
  16. #   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
  17. #   - It's NOT allowed to remove this copyright-tag                      #
  18. #   -- <a href=\"http://www.fsf.org/licensing/licenses/gpl.html\" target=\"_blank\">http://www.fsf.org/licensing/licenses/gpl.html</a>                    #
  19. #                                                                        #
  20. #   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
  21. #   Far Development by Development Team - webspell.org                   #
  22. #                                                                        #
  23. #   visit webspell.org                                                   #
  24. #                                                                        #
  25.  ########################################################################
  26. */
  27.  
  28. class Gallery {
  29.    
  30.        
  31.    function showthumb($picID) {
  32.        
  33.        global $thumbwidth;
  34.    
  35.        $pic = mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."gallery_pictures WHERE picID='".$picID."'"));
  36.        if($pic[picID]) {
  37.            $pic[gallery] = $this->getgalleryname($picID);
  38.            if(file_exists('images/gallery/thumb/'.$picID.'.jpg')) $pic[image] = '<a href="index.php?site=gallery&picID='.$picID.'"><img src="images/gallery/thumb/'.$picID.'.jpg" border="0" width="'.$thumbwidth.'"></a>';
  39.            else $pic[image] = '<a href="index.php?site=gallery&picID='.$picID.'"><img src="images/nopic.gif" border="0" width="'.$thumbwidth.'"></a>';
  40.            $pic[comments] = mysql_num_rows(safe_query("SELECT commentID FROM ".PREFIX."comments WHERE parentID='".$picID."' AND type='ga'"));
  41.            $ergebnis = mysql_fetch_array(safe_query("SELECT date FROM ".PREFIX."gallery as gal, ".PREFIX."gallery_pictures as pic WHERE gal.galleryID=pic.galleryID AND pic.picID='".$picID."'"));
  42.            $pic[date]=date("d.m.Y",$ergebnis[date]);
  43.            $pic[groupID]=$this->getgroupid_by_gallery($pic[galleryID]);
  44.            $pic['name']=clearfromtags($pic['name']);
  45.    
  46.            eval ("$thumb = \"".gettemplate("gallery_content_showthumb")."\";");
  47.            
  48.        } else $thumb='<tr><td colspan="2">Brak zdjęć w tej kategorii!</td></tr>';
  49.        return $thumb;
  50.    }
  51.    
  52.    function savethumb($image,$dest) {
  53.        
  54.        global $picsize_h;
  55.         global $thumbwidth;
  56.  
  57.         $max_x = $thumbwidth;
  58.         $max_y = $picsize_h;
  59.  
  60.         $ext=getimagesize($image);
  61.         switch (strtolower($ext[2])) {
  62.         case '2': $im  = imagecreatefromjpeg ($image);
  63.                     break;
  64.         case '1' : $im  = imagecreatefromgif  ($image);
  65.                     break;
  66.         case '3' : $im  = imagecreatefrompng  ($image);
  67.                     break;
  68.         default    : $stop = true;
  69.                     break;
  70.         }
  71.  
  72.         if (!isset($stop)) {
  73.     $x = imagesx($im);
  74.     $y = imagesy($im);
  75.    
  76.  
  77.         if (($max_x/$max_y) < ($x/$y)) {
  78.         $save = imagecreatetruecolor($x/($x/$max_x), $y/($x/$max_x));
  79.         }
  80.         else {
  81.         $save = imagecreatetruecolor($x/($y/$max_y), $y/($y/$max_y));
  82.         }
  83.     imagecopyresized($save, $im, 0, 0, 0, 0, imagesx($save), imagesy($save), $x, $y);
  84.  
  85.     imagejpeg($save, $dest, 80);
  86.  
  87.     imagedestroy($im);
  88.     imagedestroy($save);
  89.     return $result;
  90.         } else return false;
  91.    }
  92.  
  93.    function randompic($galleryID=0) {
  94.  
  95.         if($galleryID) $only = "WHERE galleryID='".$galleryID."'";
  96.         $anz=mysql_num_rows(safe_query("SELECT picID FROM `".PREFIX."gallery_pictures` $only"));
  97.         $selected = rand(1,$anz);
  98.         $start=$selected-1;
  99.         $pic=mysql_fetch_array(safe_query("SELECT picID FROM ".PREFIX."gallery_pictures $only LIMIT $start,$anz"));
  100.  
  101.         return $pic[picID];
  102.    }
  103.    
  104.    function getgalleryname($picID) {
  105.  
  106.        $ds=mysql_fetch_array(safe_query("SELECT gal.name FROM ".PREFIX."gallery_pictures as pic, ".PREFIX."gallery as gal WHERE pic.picID='".$picID."' AND gal.galleryID=pic.galleryID"));
  107.        return htmlspecialchars($ds[name]);        
  108.        
  109.    }
  110.  
  111.    function getgroupname($groupID) {
  112.  
  113.        $ds=mysql_fetch_array(safe_query("SELECT name FROM ".PREFIX."gallery_groups WHERE groupID='".$groupID."'"));
  114.        return htmlspecialchars($ds[name]);        
  115.        
  116.    }
  117.  
  118.    function getgroupid_by_gallery($galleryID) {
  119.        
  120.        $ds=mysql_fetch_array(safe_query("SELECT groupID FROM ".PREFIX."gallery WHERE galleryID='".$galleryID."'"));
  121.        return $ds[groupID];
  122.    }
  123.    
  124.    function isgalleryowner($galleryID,$userID) {
  125.        
  126.        if($userID)    return mysql_num_rows(safe_query("SELECT galleryID FROM ".PREFIX."gallery WHERE userID='".$userID."' AND galleryID='".$galleryID."'"));
  127.        else return false;
  128.        
  129.    }
  130.  
  131.    function getgalleryowner($galleryID) {
  132.        
  133.        $ds = mysql_fetch_array(safe_query("SELECT userID FROM ".PREFIX."gallery WHERE galleryID='".$galleryID."'"));
  134.        return $ds[userID];
  135.        
  136.    }
  137.    
  138.    function getlargefile($picID) {
  139.  
  140.        if(file_exists('images/gallery/large/'.$picID.'.jpg')) $file='images/gallery/large/'.$picID.'.jpg';
  141.        elseif(file_exists('images/gallery/large/'.$picID.'.gif')) $file='images/gallery/large/'.$picID.'.gif';
  142.        elseif(file_exists('images/gallery/large/'.$picID.'.png')) $file='images/gallery/large/'.$picID.'.png';
  143.        else $file='images/gallery/nopic.gif';        
  144.        
  145.        return $file;
  146.  
  147.    }
  148.    
  149.    function getuserspace($userID) {
  150.        
  151.        $size=0;
  152.        $ergebnis=safe_query("SELECT pic.picID FROM ".PREFIX."gallery_pictures as pic, ".PREFIX."gallery as gal WHERE gal.userID='".$userID."' AND gal.galleryID=pic.galleryID");
  153.        while($ds=mysql_fetch_array($ergebnis)) {
  154.            $size = $size + filesize('images/gallery/thumb/'.$ds[picID].'.jpg') + filesize($this->getlargefile($ds[picID]));
  155.        }    
  156.        return $size;        
  157.    }
  158.  
  159. }
  160.  
  161. ?>
erix
Ciężko tag dodać?
frok
żebym wiedział o co w tym chodzi to bym sam sobie poradził ;P nie wiem jaki tag i gdzie ;/
Spawnm
W tytule tematu , zobacz jak wyglądają inne tematy .
frok
nie da się już zmienić tematu
Spawnm
masz opcję edytuj, użyj jej.
frok
nie ma opcji edytuj w 1 poście w tym temacie.. mogę tylko edytować np. ten co piszę teraz
itsme
edycja postu po okreslonym czasie jest wylaczona

-----
Edcja możliwa jest przed 24 godziny od daty napisania wątku/postu.
Tag dodałem

~webdice
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.