Random generator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lazandra
    New Member
    • Sep 2007
    • 25

    Random generator

    Hi,

    I have done a random script which works perfectly fine. The problem that i'm having with is the picture.

    Below is the script

    [PHP]include("connec t.php");

    mySQL_Select_DB ("db220854136") ; //..to DB
    $potms = MySQL_Query("SE LECT * FROM listings"); //now we get all from our table and store it
    MySQL_Close($li nk); //there`s no need for connection, so we should close it

    $potm_array = ''; //sets variables to "zero" values
    $i = 0;
    while ($entry = MySQL_Fetch_Arr ay($potms)) //now we go through our DB
    {
    $potm_array[$i] = $entry; //our temporary array from which we will random pick a field key
    $i++; //now we increment our field key
    }

    $potm_id = array_rand($pot m_array); //picks a random key from array
    $potm = $potm_array[$potm_id][address]; //now we have stored our Post Of The Moment in $potm
    $potm2 = $potm_array[$potm_id][description]; //now we have stored our Post Of The Moment in $potm
    $potm3 = $potm_array[$potm_id][thumb];
    $potm4 = $potm_array[$potm_id][v_id];


    $img_chk = "SELECT name FROM thumb WHERE v_id = $potm4";
    $img_chk_result = mysql_query($im g_chk, $link) or die ("Couldn't execute query");
    $row5 = mysql_fetch_arr ay($img_chk_res ult);
    $name = $row5["name"];
    $imgName = "$thumb_path"." $name";
    $getsize = getimagesize($i mgName);
    $size = $getsize[3];
    $alt = "";
    if ($getsize[2] == 2) {
    if(($sold_over_ images == 1)&&(freetype( ) == 1)){
    if($status != "A"){
    $item_thumb = "<img src=\"thumb_sol d.php?v_id=$pot m4&status=$stat us\" alt = \"$alt\" $size border=0>";
    }else{
    $item_thumb = "<img src=\"$thumb_ur l$name\" alt = \"$alt\" $size border=0>";
    }
    }else{
    $item_thumb = "<img src=\"$thumb_ur l$name\" alt = \"$alt\" $size border=0>";
    }
    } else {
    $item_thumb = "<img src=\"$thumb_ur l$name\" alt = \"$alt\" width=\"$maxThu mbWidth\" border=0>";
    }

    if ($count != 1) {
    $bar = "<tr><td colspan=\"6\">< hr></td></tr>";
    } else {
    $bar = "";
    }


    echo "$potm <br>";
    echo "$potm2<br> ";
    echo "$item_thum b;"[/PHP]

    Cheers :-)
  • coffear
    New Member
    • Nov 2007
    • 20

    #2
    You say the only problem is with the image. Are you actually going to tell us what that problem is or should we guess?

    An error message would be nice, if not an actual description of the error is needed.

    Comment

    • Lazandra
      New Member
      • Sep 2007
      • 25

      #3
      The error is that the picture isn't showing.

      Comment

      • coffear
        New Member
        • Nov 2007
        • 20

        #4
        when you navigate to the page look in the source and see if the image loadtion is as it should be.

        Comment

        • helraizer1
          New Member
          • Mar 2007
          • 118

          #5
          add

          [code=php]

          error_reporting (E_ALL);

          ini_set('displa y_errors', true);



          [/code]

          to your code. Then let us know of any errors that appear

          Comment

          • realin
            Contributor
            • Feb 2007
            • 254

            #6
            here is something which i have been using, it picks the pictures from the wallpaper folder, create there thumbnails(ever ytime) and store them in THUMBS folder. Then display those thumbs with the link to original big picture. Hope this helps you with your real script, its like a prototype for you :)

            enjoy
            cheers !

            [PHP]function random_pic()
            {
            $i=0;
            $j=0;
            $img=array();
            $fil=file('./inc/wall.txt');
            while($i<4){
            srand ((double) microtime() * 1000000);
            $a = rand(0, sizeof($fil) - 1);
            $img[$i]=$fil[$a];
            $img[$i]=preg_replace('/[\\r?\\n]/',"",$img[$i]);
            $i++;
            }

            //print_r($img);
            while($j<4){
            $this->createthumb( './wallpaper/'.$img[$j],'./wallpaper/thumbs/'.$img[$j],150,150);
            $j++;
            }

            ?>
            <div id='album'>
            <table id='alb' cellspacing="2" cellpadding="0" border="0" >
            <tr><td><a href='http://yourdomain.com/wallpaper/<?php echo $img[0]; ?>'><img src='http://yourdomain.com/wallpaper/thumbs/<?php echo $img[0]; ?>' alt='Random Pic' /></a></td>
            <td><a href='http://yourdomain.com/wallpaper/<?php echo $img[1]; ?>'><img src='http://yourdomain.com/wallpaper/thumbs/<?php echo $img[1]; ?>' alt='Random Pic' /></a></td></tr>
            <tr><td><a href='http://yourdomain.com/wallpaper/<?php echo $img[2]; ?>'><img src='http://yourdomain.com/wallpaper/thumbs/<?php echo $img[2]; ?>' alt='Random Pic' /></a></td>
            <td><a href='http://yourdomain.com/wallpaper/<?php echo $img[3]; ?>'><img src='http://yourdomain.com/wallpaper/thumbs/<?php echo $img[3]; ?>' alt='Random Pic' /></a></td></tr>
            </table>

            </div>
            <?php
            }[/PHP]

            function to create thumbs::

            [CODE=PHP]function createthumb($na me,$filename,$n ew_w,$new_h){

            $system=explode ('.',$name);
            if (preg_match('/jpg|jpeg/',$system[2])){
            $src_img=imagec reatefromjpeg($ name);
            }
            if (preg_match('/png/',$system[2])){
            $src_img=imagec reatefrompng($n ame);
            }

            if (preg_match('/gif/',$system[2])){
            $src_img=imagec reatefromgif($n ame);
            }

            $old_x=imageSX( $src_img);
            $old_y=imageSY( $src_img);
            if ($old_x > $old_y) {
            $thumb_w=$new_w ;
            $thumb_h=$old_y *($new_h/$old_x);
            }
            if ($old_x < $old_y) {
            $thumb_w=$old_x *($new_w/$old_y);
            $thumb_h=$new_h ;
            }
            if ($old_x == $old_y) {
            $thumb_w=$new_w ;
            $thumb_h=$new_h ;
            }

            $dst_img=ImageC reateTrueColor( $thumb_w,$thumb _h);
            imagecopyresamp led($dst_img,$s rc_img,0,0,0,0, $thumb_w,$thumb _h,$old_x,$old_ y);


            if (preg_match("/png/",$system[2]))
            {
            imagepng($dst_i mg,$filename);
            } else {
            imagejpeg($dst_ img,$filename);
            }
            imagedestroy($d st_img);
            imagedestroy($s rc_img);
            }
            [/CODE]

            And yeah i forgot to mention the names of the files which are stored in the file wall.txt are only displayed or take care of. So you can put all your pics in the folder wallpaper then you can run this file to automatically create a wall.txt for you.. Also make sure you change the paths according to your needs.
            [CODE=PHP]
            <?php
            $handle=opendir ('../wallpaper');
            while (false!= $file=readdir($ handle)){
            if ($file != "." && $file != ".." && $file!="thumbs" )
            $content.=$file ."\r\n";

            }

            $filename="wall .txt";

            fopen($filename ,"w+");

            if(is_writable( $filename)){

            if(!$handle2=fo pen($filename,a ))
            {

            echo"cannot open file";
            exit;
            }

            if (fwrite($handle 2, $content) === FALSE)
            {
            echo "Cannot write to file ($filename)";
            exit;
            }


            fclose($handle) ;

            }
            else
            {
            echo "File is not writeable";
            }


            ?>[/CODE]

            Comment

            Working...