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 :-)
5 1145
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.
The error is that the picture isn't showing.
when you navigate to the page look in the source and see if the image loadtion is as it should be.
add -
-
error_reporting(E_ALL);
-
-
ini_set('display_errors', true);
-
-
-
-
to your code. Then let us know of any errors that appear
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:: - function createthumb($name,$filename,$new_w,$new_h){
-
-
$system=explode('.',$name);
-
if (preg_match('/jpg|jpeg/',$system[2])){
-
$src_img=imagecreatefromjpeg($name);
-
}
-
if (preg_match('/png/',$system[2])){
-
$src_img=imagecreatefrompng($name);
-
}
-
-
if (preg_match('/gif/',$system[2])){
-
$src_img=imagecreatefromgif($name);
-
}
-
-
$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=ImageCreateTrueColor($thumb_w,$thumb_h);
-
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
-
-
-
if (preg_match("/png/",$system[2]))
-
{
-
imagepng($dst_img,$filename);
-
} else {
-
imagejpeg($dst_img,$filename);
-
}
-
imagedestroy($dst_img);
-
imagedestroy($src_img);
-
}
-
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. -
<?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=fopen($filename,a))
-
{
-
-
echo"cannot open file";
-
exit;
-
}
-
-
if (fwrite($handle2, $content) === FALSE)
-
{
-
echo "Cannot write to file ($filename)";
-
exit;
-
}
-
-
-
fclose($handle);
-
-
}
-
else
-
{
-
echo "File is not writeable";
-
}
-
-
-
?>
Sign in to post your reply or Sign up for a free account.
Similar topics |
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?...
|
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.
|
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
|
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...
|
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...
| |
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.
|
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...
|
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?
|
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);
|
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.
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |