473,789 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random generator

Lazandra
25 New Member
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 :-)
Nov 22 '07 #1
5 1145
coffear
20 New Member
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.
Nov 23 '07 #2
Lazandra
25 New Member
The error is that the picture isn't showing.
Nov 23 '07 #3
coffear
20 New Member
when you navigate to the page look in the source and see if the image loadtion is as it should be.
Nov 23 '07 #4
helraizer1
118 New Member
add

Expand|Select|Wrap|Line Numbers
  1.  
  2. error_reporting(E_ALL);
  3.  
  4. ini_set('display_errors', true);
  5.  
  6.  
  7.  
  8.  
to your code. Then let us know of any errors that appear
Nov 25 '07 #5
realin
254 Contributor
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::

Expand|Select|Wrap|Line Numbers
  1. function createthumb($name,$filename,$new_w,$new_h){
  2.  
  3.     $system=explode('.',$name);
  4.     if (preg_match('/jpg|jpeg/',$system[2])){
  5.         $src_img=imagecreatefromjpeg($name);
  6.     }
  7.     if (preg_match('/png/',$system[2])){
  8.         $src_img=imagecreatefrompng($name);
  9.     }
  10.  
  11.         if (preg_match('/gif/',$system[2])){
  12.         $src_img=imagecreatefromgif($name);
  13.     }
  14.  
  15. $old_x=imageSX($src_img);
  16. $old_y=imageSY($src_img);
  17. if ($old_x > $old_y) {
  18.     $thumb_w=$new_w;
  19.     $thumb_h=$old_y*($new_h/$old_x);
  20. }
  21. if ($old_x < $old_y) {
  22.     $thumb_w=$old_x*($new_w/$old_y);
  23.     $thumb_h=$new_h;
  24. }
  25. if ($old_x == $old_y) {
  26.     $thumb_w=$new_w;
  27.     $thumb_h=$new_h;
  28. }
  29.  
  30. $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
  31. imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
  32.  
  33.  
  34. if (preg_match("/png/",$system[2]))
  35. {
  36.     imagepng($dst_img,$filename); 
  37. } else {
  38.     imagejpeg($dst_img,$filename); 
  39. }
  40. imagedestroy($dst_img); 
  41. imagedestroy($src_img); 
  42. }    
  43.  
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.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $handle=opendir('../wallpaper');
  3. while (false!= $file=readdir($handle)){
  4. if ($file != "." && $file != ".." && $file!="thumbs") 
  5. $content.=$file."\r\n";
  6.  
  7. }
  8.  
  9. $filename="wall.txt";
  10.  
  11. fopen($filename,"w+");
  12.  
  13. if(is_writable($filename)){
  14.  
  15.     if(!$handle2=fopen($filename,a))
  16.         {
  17.  
  18.             echo"cannot open file";
  19.             exit;
  20.         }
  21.  
  22.         if (fwrite($handle2, $content) === FALSE) 
  23.         {
  24.            echo "Cannot write to file ($filename)";
  25.             exit;
  26.         }
  27.  
  28.  
  29.         fclose($handle);
  30.  
  31. }
  32.     else
  33.     {
  34.         echo "File is not writeable";
  35.     }
  36.  
  37.  
  38. ?>
Nov 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3703
by: Brandon Michael Moore | last post by:
I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a specified range), random strings (specifying allowed characters and a distribution of lengths), or choose randomly between several generators (for better control of the distribution of values). Is there any library for this sort of thing in Python?...
28
3707
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are appreciated.
3
7381
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I have utilised the following random number source code http://www.agner.org/random/ What I have found is that there is a problem with seeding. The code generates a seed based on time(0). I have found that I need to increment
70
6287
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
5
3353
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
104
5194
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a better way than to fill an array of range 0... RAND_MAX with pre-computed primes and using the output of rand() to index into it to extract a random prime.
13
3201
by: porterboy76 | last post by:
If you only use a 32 bit seed for a random number generator, does that mean you can only ever produce a maximum of 2^32 (approx 4 billion) different sequences? What about the Mersenne Twister, with it's massive period of 2^19937-1. Will you only ever have access to a tiny portion of this ring of numbers, if you only use a 32-bit seed? Will this set of sequences be confined to the beginning of the period, ie, your sequence will have to...
2
3394
by: Matthew Wilson | last post by:
The random.jumpahead documentation says this: Changed in version 2.3: Instead of jumping to a specific state, n steps ahead, jumpahead(n) jumps to another state likely to be separated by many steps.. I really want a way to get to the Nth value in a random series started with a particular seed. Is there any way to quickly do what jumpahead apparently used to do?
3
4687
by: Daniel | last post by:
Hey guys Using Random(), how random is it, is it possible to be predicted? I have a requirement for a very good random number generator. I was doing something such as: Random randomSeed = new Random((int)_seedTimer.ElapsedTicks); _random = new Random(randomSeed.Next(0,99999999)); return random.Next(min, max);
11
3024
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays of values. I get a random index value for each array so I can pull the data from them.
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8998
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4078
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.