PHP - Random Content Selctor...
Hi I'm wondering how I would go by making some sort of scrip for my website that loads random content from different files on my web server. Preferably php coding and maybe some mysql coding for an example I would like to have different folders on my web server lets say I have ( File 1 ) and in file 1 I have files named "cover.jpg" and "description.txt" and maybe some other files too and the same thing in other files on the web server
So how would I go by making some thing that can load up these different files on the web server, like I said that will load up the content in each of the files every time the page refreshes or press of a button. Thanks Similar TutorialsHi to everyone , I have used PHP for some basic things in my previous website design but am now venturing into another website for which I have a more complex use for PHP. I plan on making business directory for my local area. People will click on the area of their choice followed by the business type that they require. Then on the results page, they will have a list of all the business types in that particular area. What I would like to be able to do is rather than have the results displayed on the page like this : A Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Best Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Top Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx I would like it so that the same businesses are displayed on the page but either: 1) In a random order each time someone loads the page or 2) In a random order changed every hour The aim is so the businesses all have a shot at appearing nearer the top and aren't penalised for the 1st letter of their company name. Any help on this would be much appreciated, Thank You This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=319085.0 As above, I have a lottery style site that picks a random number between 1-8 but my users complain for some reason that this is not enough. So i was told to look into using fopen and random.org to generate a random number. Anyone have experience of this and perhaps a code snippet for me to look at and possibly use? help will be appreciated. Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. Hi, I will start off trying to explain what I am trying to make the best I can. What I want to create is a script that gets the gold value from this website: http://www.lbma.org.uk/pages/index.cfm?page_id=46&title=current_statistics and then save it to a variable which I will use to calculate values of different gold karats. Here is the content in bold I need on the website I linked: Quote LONDON GOLD FIXING USD GBP EUR AM 1588.00 1005.127 1251.083 PM 1589.50 1004.741 1249.803 So what help do I need? Well, I don't expect you to figure out the calculating part for me but some help how to get that content pointed out above and save it to a variable is what I would appreciate getting some help with. I don't know much PHP, only some and I have been trying to figure this out for a day now without any success. I suppose php get contents and/or curl should be used here but I don't know how really. I would very much appreciate the help I can get on this. Thank you! This is the Code i am using. This is show error: Fatal error: Call to a member function item() on a non-object in /home/domain/public_html/forum/file/Test.php on line 35 Code: [Select] <?php $xml=("http://www.vn-zoom.com/external.php?type=RSS2&forumids=77"); $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); //get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; //output elements from "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); //get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); $i=1; // $i = 1 to n (I use For here). { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; // If i remove this, it will work....//////////// $item_content=$x->item($i)->getElementsByTagName('content') ->item(0)->childNodes->item(0)->nodeValue; ///////////////////////////////////////////////////// echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); echo ("<br />"); echo ($item_content . "</p>"); } ?> Please help me Fix this Code to Get content of Tag Name <content:encoded> Thanks I know this is not coding.. However... How tolerant is PHP from generating a random output from 1000s of entry columns in a mysql database. I would like to make a script that would potentially pick one of a 1000 results at random. is this a problem with being ran multiple times? I'm just searching for some input on a function I saw and wanted someone who could explain to me what this function would mean. As I have the same db structure and was curious specifically to know what sort of values I should have inside of the fields for varcharfield and textfield. function customfieldinput($fedid,$id,$groupid,$styleid) { $query = "SELECT field.id as getfieldid, field.is_custom as getiscustom, field.fullname as getfullname, customfields.id as getcustomfieldid, customfields.varcharfield as getvarchar, customfields.textfield as gettext FROM efed_list_fields as field LEFT JOIN efed_content_customfields as customfields ON ( field.id = customfields.field_id and customfields.character_id = '$id' ) WHERE field.fed_id = '$fedid' and field.style_id = '$styleid' and field.group_id = '$groupid' and field.enabled = '1' and field.is_custom > '0' ORDER BY field.is_custom,field.fullname"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc($result)) { $fieldarray=array('getfieldid','getiscustom','getfullname','getvarchar','gettext','getcustomfieldid'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { $$fieldlabel=$row[$fieldlabel]; $$fieldlabel=cleanquerydata($$fieldlabel); } } if ((isset($getcustomfieldid)) && ($getcustomfieldid > "0")) { $update = "update"; } else { $update = "new"; } if ($getiscustom == "1") { print "<tr>\n"; print "<td width=120 class=rowheading>".$getfullname.":</td>"; print "<td class=row3><textarea name=\"custom".$getfieldid.$update."\" class=\"textarea490x100\">"; if ((isset($gettext)) && ($gettext != "")) { print $gettext; } print "</textarea></td>\n"; print "</tr>\n\n"; } else { print "<tr>\n"; print "<td width=120 class=rowheading>".$getfullname.":</td>"; print "<td class=row3><input type=text name=\"custom".$getfieldid.$update."\" class=fieldtext490"; if ((isset($getvarchar)) && ($getvarchar != "")) { print " value=\"".$getvarchar."\""; } print "></td>\n"; print "</tr>\n\n"; } if (isset($getcustomfieldid)) { unset ($getcustomfieldid); } if (isset($getvarchar)) { unset ($getvarchar); } if (isset($gettext)) { unset ($gettext); } } } how do I pull out two random integers at the same time without ever possibly choosing the same integer twice? How would I make it so that for every set of data where a fieldname is 1+ it picks a random one out. For example User Hit Luke 0 Peter 1 Alex 3 Peter 1 For every value where Hit is 1 or over it selects out of the query results a random username. i wanted to choose 5 random numbers from 0-20. each number represents an index in an array. is there a way to pick out 5 random items from the array. say if random number generator piked a number 22, the last item in the array is at index 20, it wud then have to go to index 0. thanks! here is the database: its a facebook app i want that my sql will choose every time random but considerate in the sex parameter. i mean that if the user is boy i will put it in parameter and boys is num-1 girls-0 and if the user is boy it will run random sql just on the boys and if its girls so random on the girls here what i did: $sql = "SELECT * FROM pcm ORDER BY RAND() LIMIT 1"; $Recordset3 = mysql_query($sql) or die(mysql_error()); $row2 = mysql_fetch_object($Recordset3); print_r($row2); but for some reason i get an error that the database is not selected maybe i didnt select my database right? please help tnx.... hello, i am trying to see how i can pick a random number between 1-15 and exclude certain numbers. so i have a staff list that once a random number is created it inserts it into the staffnumber field. so the next time i create a random number for a staff, i want to make sure that the random number doesnt select an existing staffnumber. thanks! I want to loop through all the values of an array.. but each time, JUST FOR THE LOOP, i want to go through the array values randomly. How do you suggest I do this? Hi Guys, I have a php script to upload a photo to a mysql table. This works great, until someone uploads a file with the same name, then it replaces the old one. Bad times! So Ive researched it and I have put a timestamp on the filename and it uploads with the correct timestamp in the images folder. However the data that it uploads to the table is just the original filename, ie it doesnt stamp the filename in the table therefore they dont match... Any ideas... <?php include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { //Photo Upload //This is the directory where images will be saved $name=time(); $target = "images/"; $target = $target .$name. basename( $_FILES['photo']['name']); //This gets all the other information from the form $photo = ($_FILES['photo']['name']); //Pause Photo Upload foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '{$_FILES['photo']['name']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); //Unpause Photo Upload //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "<br />The file ". basename( $_FILES['photo']['name']). " has been uploaded. <br />"; } else { //Gives and error if its not echo ""; } //End of Photo Upload echo (mysql_affected_rows()) ? "<br />Edited Branch.<br />" : "<br />Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> The purpose of this function is to go to the characters table and grab all of the characters that have a statusID of one however I want it to limit it to any ONE of those characters as this is a random image it's going to show and then I want it to have that charactes shortName and then use it to find their spotlight image from inside of the images/spotlight folder. All its showing right now in its spot is the the filename of the image when I call this function. function spotlight(){ $query = "SELECT * FROM characters WHERE characters.statusID = 1 LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $labels = array('shortName'); $img = array(); if($handle = opendir('images/spotlight/')) { $count = 0; while (false !== ($file = readdir($handle))) { if(strlen($file) > 2){ $img[$count] = $file; $count++; } } } echo $img[rand(0, (count($img)-1))]; } Is there anyway in MySQL you can select a random record in a table? I normally do this by generating a random number first and then using that number to find a record but was wondering if there is an easier way. Thanks for any help. Hi Guys I have a code what inserts very simple queries to database, im trying to add a random reference number for each enrty using $reference = rand(111111111111,999999999999); but each time I add an entry it gives me the same random number previously generated for previous entry can you help pleasE? I need some help working out this MySQL query:
I need it to pull a random quote, that hasn't been used before (that's the 'checked' part of the query), and it needs to find it based on a specific category. I am using this alongside PHP with MySQLI Prepared method.
SELECT `id`, `word`, `def` FROM `dictionary` AS `r1` JOIN (SELECT (RAND() * (SELECT MAX(`id`) FROM `dictionary`)) AS `id`) AS `r2` WHERE `r1`.`id` >= `r2`.`id` AND `category`=? AND `checked`=0 ORDER BY `r1`.`id` ASC LIMIT 1This query yields an error stating that the id column is ambiguous. Okay, minor issue, but not sure how to resolve. I have a form that processes through PHP and has it's fields validated with JS and sends the data to an e-mail address and a database. It works fine, but there are random times where a submitted entry will show up blank in the e-mail and not be in the database at all, any ideas on what might be causing this? Thanks. |