
Deven
User
May 1, 2005, 6:04 PM
Post #10 of 50
(42194 views)
Shortcut
|
|
Re: [jasper] Random Listings Script
[In reply to]
|
Can't Post
|
|
It may be the way your server handles PHP virtual(). virtual() is an Apache-specific function which is equivalent to <!--#include virtual...--> in mod_include. This function works only when PHP is compiled as an Apache module, since it uses the Apache API for doing sub requests. You may want to try this: Comment out line 47 by adding 2 forward slashes in front of it ( i.e.... // ). Then on the next line down add this: echo $listing_num[0]; You should see a different listing number each time you reload the page. If this works ok, then can build the whole thing right in this script. Here's an example of the whole script: <?php //Path to listing.dat.cgi file. $path = "cgi-bin/listman/data/listing.dat.cgi"; //Put listings into an array. $array = file($path); //Remove first 3 lines of listing.dat file. array_splice($array,0,3); //Randomize the array. $element = $array[rand(0, count($array)-1)]; //Separate each field. $listing_num = explode("¡", $element); //Strip everything past the 75th field. array_splice($listing_num, 75); //If no image, let's use a default one. if ($listing_num[4] == ''){ $listing_num[4] = ('nophoto.jpg'); } else { $listing_num[4] = $listing_num[4]; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Random Listing</title> </head> <body> <table border="0" cellpadding="0" style="border-collapse: collapse" width="150" id="table1" bgcolor="#000080"> <tr> <td> <p align="center"><font color="#FFFFFF"><b>Random Listing</b></font></td> </tr> </table> <table border="1" width="150" bordercolor="#003366" bgcolor="#DFDFDF"> <tr> <td> <p align="center"><br><a href="http://yourdomain.com/cgi-bin/listman/exec/search.cgi?view=<?php echo $listing_num[0];?>"><img src="http://yourdomain.com/listman/listings/images/<?php echo $listing_num[4];?>" border="0" width="140"></a></p> <font face="Trebuchet MS" size="2" color="#800000"> <?php echo $listing_num[14];?><br> <?php echo $listing_num[16]." ".$listing_num[17];?><br> <?php echo $listing_num[19];?><br> <a href="http://yourdomain.com/cgi-bin/listman/exec/search.cgi?view=<?php echo $listing_num[0];?>">details...</a><br></font> </td> </tr> </table> <table border="1" cellpadding="0" style="border-collapse: collapse" width="150" id="table3" bgcolor="#000080"> <tr> <td> </td> </tr> </table> <br> </body> </html> Now you'll see from above I looked in my listing.dat.cgi file and examined each field to see what it represents. Starting with the first field $listing_num[0] is my listing number, followed by the separator "¡", then my second field would be $listing_num[1], 3rd field would be $listing_num[2], and so on... Also I have an if,else statement in this script that says if no image is found, use an image which i created and uploaded to my \listman\listings\images folder. It's a jpg image that says "No photo available". You can insert each field you want to display using this: <?php echo $listing_num[x];?> "x" represents the field position of the item to display. After your done, make sure this file's name ends with the .php extention. Then you can use a include statement in your .shtml page to include this php page. Example: <!--#include file="random.php" --> Hope this helps everyone who wants a random listing to display perhaps on their home page. ~~~Deven
(This post was edited by Deven on May 1, 2005, 7:09 PM)
|