Randomly Select Records
I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh. Question 1: how to get a "random" selection from the database, giving more priority to the last inserted (the ones with higher articleID) Question 2: I'd like to provide one article by client. I won't show 3 articles from the same client only because he has been the last one to insert his articles. So I must randomly select by choosing between last articleID, but only one per clientID. simplified table is:
articleID
clientID
details
price.
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Randomly Select A Row
I have to do a script where a user fights an enemy. There are many to choose from all for differn't levels in which the user is at. I need to first (SELECT * FROM creep_data WHERE minlvl < '".$user[lvl]."' AND maxlvl > '".$user['lvl']."'") After I have all of the possible monsters I need to randomly select one of these and retrieve all of the data about it. How could I go about doing this ?
View Replies !
View Related
Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?
View Replies !
View Related
How Do You Select All Records In The Month You Are In?
I have records in the database - one of the fields is a date field. I want to select all records in the database that are in the month I am in. For example, if it is the 12th September 2002 today and I go to the page then it selects all records from September 2002. If it is the 4th June it selects all records in June etc.
View Replies !
View Related
Select Multiple Records
I have an application that uses mysql database. Several records are retrived from the database. To enable users to select multiple records, I've used checkboxes by the side of each record. However, the checkbox does not retrieve their value from the database, neither do they update the database. I just thought that by setting the value of the checkbox, I could determine the selected checkboxes and insert the corresponding records into the database. The selected records whose checboxes have been set are then inserted into another table. Or updated as I may also need to update some. My problem,however, is how to determine the selected records and then do multiple inserts into the database table?
View Replies !
View Related
Select Two Weeks Of Records
ok - so i've got some entries with dates in my db. I thought i had it but its not quite there yet. If today is 20061017 and i want to look 3 weeks into the future its not as simple as addings 21 days. How can i get the month to change automatically after it reaches the last day of the month? Code:
View Replies !
View Related
Copy Select Records To New Table
In the table Step I have multiple records for each given id. I want to save the current list of records for an id to a new Step_Old table so I can look back at what I had at a given point in time, since the records for an id in the Step table will change over time. Now the question... does anyone have a slick way to do this, or do I need to Select all the records I want to save and then save them one by one with a while loop into the Step_Old table?
View Replies !
View Related
How To SELECT Records WHERE Field Contains A Particular String?
I need to SELECT records WHERE a string matches the content of a field... eg. I have field values like: Phone namePhone name pinkPhone name bluePhone name polka-dot What I want is to have a MySQL query which selects ALL records which match the search term, eg. 'Phone name' returns all of the above, but not 'Phone': Currently my query looks like this: SELECT * FROM [table_name] WHERE [field_name] LIKE '%s' ORDER BY [value] ASC
View Replies !
View Related
Very Slow MySQL SELECT Query After 11 Records
I have a very weird problem I moved my database to new IIS 6.0 + PHP 4.3 + MySQL 4.0 setup. I tried to check with myphpadmin if everything works fine, but I couldn't browse my table (125 records). I used SELECT option and found out that SELECT query up to 11 records is ok, but after that, even if I choose to limit query to 12 records, it just hangs. I tried selecting from the beginning of the table and from the middle - same thing, but when I run query localy on mysql console, everything works fine
View Replies !
View Related
Select Distinct Records Within 2 Separate Tables
I have 2 tables - 1) - paid counties 2) - free counties and I want to search both to find a distinct list of the counties used. Is there a way to search the first list (save the data into an array), then add ONLY the distinct counties from the free table into the array. Then read all the data out of the array sorted by CountyName,CountyID.
View Replies !
View Related
Loop To Select And Update Records Using Classes
I am using a group of classes to manipulate MySQL tables. I would like to be able to go through a table one line at a time to convert fields from all upper case to word upper case. The problem I have, I think anyway, is that my result set from the first query is abandoned by the second query. I am wondering if there is an easy way around this? Code:
View Replies !
View Related
Select Query To Get Only Todays Date Records
I want to use the following query to show only users who registered today with todays date.format(m/d/y)field name is: a.date_registration select a.id, a.fname, a.sname, a.status, a.login, a.login_count, b.lang_1 as gender, a.email from pro_user a left join pro_reference_lang_spr b on b.table_key=཈' and b.id_reference=a.gender where a.date_registration = (Todays Date m/d/y) order by a.login limit 0, 10 0, 10
View Replies !
View Related
Select All The Records In A Table That Were Input Last Month
I am trying to select all the records in a table that were input last month, example:if month today is October select all record with month of September The query I am using is PHP Code: SELECT payments.*, members.* FROM payments, members WHERE payments.coupon_id = 餞C554360' AND payments.member_id = members.member_id AND payments.begin_date < NOW() - INTERVAL(1 MONTH) This display an error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'MONTH)' at line 1 I am not sure if my query is written correctly.
View Replies !
View Related
Create A Sql Query That Will Select Records By Selecting A Month
I am trying to create a sql query that will select records by selecting a month. So for example I have to create a query rhat will select all entries between 1st jun and 1st july (1117609200 and 1120201200) which should not be that hard. Is there a function that will generate what the timestamps should be automatically instead of me having to calculate them manually.
View Replies !
View Related
Select Records By The Year From A Mktime() Stamp In The Database
I'm trying to select records by the year from a mktime() stamp in the database. I thought I could do it this way: PHP Code: $new_date = "2006"; $query = "select date, DATE_FORMAT(date,'%Y') AS year from articles where year = $new_date"; But I'm doing something wrong and haven't been able to figure out what it is. 2 hours of reading documentation and I'm missing something.
View Replies !
View Related
Displaying Priorty Records And Normal Records In The One Dataset.
I have a page which displays the records from the database and uses paging to display the records in groupes of 10 per page. I now want to be able to show results depending on the database field (display) in the database (can be set to either "full" or "limited"). If the record and the field display is equal to "full" i want to then display this record at the top of the record set and display all the fields. If the record is equal to "limited" i want to display different results and they must show after all the records which are equal to "full". I can't output two different recordsets as i use paging and only want to show 10 records per page. Code:
View Replies !
View Related
DELETE RECORDS - Database Adding New Records
iv got the database adding new records, and now I want it to display all of the records that are there buy name and id number, then i want u to be able to type in the id number of the customer u wish to delete and it shoudl delete it, sounds good buts its not actually deleting the record. it says it does, but its not doing it. Code:
View Replies !
View Related
Problems With The Listing Of Records, Editing Of Records
I'm having problems with the listing of records, editing of records, and deleting of records. I'm not sure what I'm doing wrong. The listing script is calling the add entry script. So I add the record, the database is updated, and nothing else happens. I don't get a list of records from that table. When I did SQL programming off the mainframe, you did a simple select statement. I'm not sure why the PHP list script is calling the add entry script. Code:
View Replies !
View Related
Randomly Calling On Something By Day
I would like to change some php to calling on something by day. The one I have only calls on something randomly. Do you know how I can alter this string to accomodate this? $banner_no = (rand()%(count($s_con)-1)); Just so you know what the above does, gets a random number which is in the content of my file. for instance if I have 1-some text 2-different text 3-some other text It grabs one of these numbers and the text along with it to display randomly. I would like it to display by day and in order instead.
View Replies !
View Related
Sessions Randomly
I set a session value. If i reload the page anywhere between 1 and 100 times, it will at one point, randomly drop. It could by on the first reload, or 51st, or 100th, or sometimes more.
View Replies !
View Related
Randomly Pairing
I have a function that generates random numbers and sticks them into an array based on the number of people I have in the table. See below: PHP Code: unset($arr); $arr = array(); while ( count($arr) < $count ) {Â Â Â Â Â Â Â Â $x = mt_rand(1,$count);Â Â Â Â Â Â Â Â Â if (!in_array($x,$arr)) { Â Â Â Â Â Â Â Â $arr[] = $x; Â Â Â Â } }.......
View Replies !
View Related
Shell_exec() Works Randomly
In another post I told about PHP not being able to create dates earlier than 1970, so until I can get PHP to do so, I am using a small perlscript to do it. It looks like this: //$in[date]*is something like "1943-10-12"; $unixtime = shell_exec("bin/converttime.pl $in[date]"); Problem is, this fails once ever twenty times or so - shell_exec() doesn't return anything. This is true of another place where I use shell_exec() to run /usr/bin/cal so I don't think the problem is with the application I am trying to execute.
View Replies !
View Related
Session Randomly Being Destroyed
So I log in again, reload my webpage a couple of times, and then I "log out". This means that when I refreshed the login inputs show up. This is bad because I have those show up if a person is not logged in(meaning the sessions aren't set). This means that the sessions are either being destroyed, or aren't being set right. But the last option is that my host is messed up, because I have the same thing running at another host and it works fine.
View Replies !
View Related
Randomly Selected Account
I have an application that I need users to be logged into automatically without creating an id. I have setup a database with users names as user1, user2, user3, and so on, and a field called in_use. I can make php set the in_use field in the database to yes when the page is loaded and I can get php to select the first available username. I can't however get the database to reset the in_use field by itself (if the user closes the window insted of clicking log out).
View Replies !
View Related
Randomly Not Generated Whole Page
I bump into a weird problem. Randomly a page is not fully generated. When I reload a page most of the time it's OK but sometimes (without any apparent logic) only a part is generated and sometimes some PHP errors appear (about missing functions, unfisnished regexp etc.) as though some scripts were not properly parsed or loaded. The application itself ran without any problems on other two servers. The server where the problem occurs is FreeBSD, PHP4 with AfterBurner accelerator. Unfortunately, I don't have access to the server, so I cannot check further settings and logs. Does anybody have an idea what can be going on?
View Replies !
View Related
Randomly Generating A Joke
What I want is that in the jokes section of site, I want a jokes to appear daily (today's Joke) Whats the best way to do that. Would it be better if there is a link to Today's Joke & it pops up after clicking it, or its better that it takes you to the jokes page and displays it there.?
View Replies !
View Related
Randomly Chose A Row In Database
How can I randomly chose a row in database, so that each time I refresh the browser a different row will show up, and once gone thru all the rows, start over ? I have 50 links in db, only want to show one at a time, but also want to go thru each row instead of randomly chosing one, otherwise one will be shown more then others.
View Replies !
View Related
How To Tell If Randomly Selected Account Is In Use?
I have an application that I need users to be logged into automatically without creating an id. I have setup a database with users names as user1, user2, user3, and so on, and a field called in_use. I can make php set the in_use field in the database to yes when the page is loaded and I can get php to select the first available username. I can't however get the database to reset the in_use field by itself (if the user closes the window insted of clicking log out).
View Replies !
View Related
Retrieve Randomly Data
I have store in a database some question with four answers for each question. I want retrieve randomly 20 questions from the database. Also I have to mix the answers as I echo them outâ€.
View Replies !
View Related
Foreach Work Randomly
I have this code: $new_names = array("Jonh Trevor", "Peter Lowe", "David Cassey", "Peter Trevor", "David Trevor"); foreach($new_names as $value) { if(in_array(strtolower($value), $names_inserted)) { echo $value." name already inserted<br>"; } $firstnames = array("Jonh", "Peter", "David"); $lastnames = array("Cassey", "Lowe","Trevor"); $new_names = $firstnames[array_rand($firstnames)]." ".$lastnames[array_rand($lastnames)].
View Replies !
View Related
Session Data Randomly Lost.
When viewing my php page using IE6.0, I am losing my session data. In the first page I am setting a value to the session variable. In the next page "SOME TIME" the value of the session variable is not same as what I set in the previous page. My session data is lost. This is happening very frequently in IE6.0 sp2 and very less frequently in IE6.0 sp1. In my php script I am using Ouput Buffering. If I disable my Output Buffering php script works fine, Session data is not lost. The random loss of session data is happening only when Output Buffereing is enabled. I donot understand the dependency between Ouput buffering and IE. I donot want to disable the ouput buffering also. Can anybody help me out in fixing this problem.
View Replies !
View Related
Randomly Selecting 4 Elements From An Array
I'm a newbie to php/mySQL interactions and I'm having a couple of problems. I have stored in a mySQL table a list of image file references and website links associated with them (basically banner ads). I have a query that will pull out all the banner ads associated with a particular category (i.e restaurant ads only display in the restaurant section) but there are only 4 advertsing spaces on the page and 10 ads returned by the query from the database. I have put the result of the query into an array, but what I want to do now is randomly select 4 elements (ads) from this array and populate another array with them. Then I can run them through a loop and print the ads to the page. Can anyone show me how to select the elements of an array randomly and then populate the new array?
View Replies !
View Related
MySQL Connection Dies Randomly?
I've spent the morning searching google groups without success, so I'm hoping someone has an idea of what's going on. I connect to a database like this: $catdb = @mysql_connect("localhost", "username", "password"); @mysql_select_db("mydatabase",$catdb); I have a problem on one script where I'll do a query using this connection, and it doesn't return anything. No results, no errors, nothing. But when I copy those two lines and paste them right above the query, it works fine. It's like the query dies between then and here. The first connection string isn't inside a function, but is the first two lines of the script. What would cause a connection to not respond? I'd at least expect a "$catdb is not a valid mysql link" or similar, but no error? What's going on?
View Replies !
View Related
Randomly Changing Variable Values
I have a function which outputs an image to a filename which is specified by a combination of a variable inputted into the function, and a hard-coded location. The variable is being inputted to the function correctly - i placed an echo command the line before the function is called and that value is correct..... however an echo command within the function seems to show a different value. It is this changed value which is being used as the location, not the correct one which is being sent to the function 8081_B12345_53444900_10 becomes 8081_B12345_53444900_14 8081_B12345_53444900_U99 becomes 8081_B12345_53444900_V03 8081_B12345_53444900_aa becomes 8081_B12345_53444900_ae Any idea what is causing this? It shouldn't be my coding as between the two echo commands all that happens is the value is passed to the function.
View Replies !
View Related
Make A Number Plus Or Minus Randomly
only way i could think of is this: $TheNumber = 500; PHP Code: $rand = rand(0,1); if($rand == 1){ $TheNumber= '-'.$TheNumber.'' } This works but i have serveral numbers to do this with. and this would equal alot of code to make 3 numbers plus or minus. any other way to do this?
View Replies !
View Related
Randomly Overright File Script
I need a script that will overright an image file with an image from a list/directory. There can be two seperate files (the script and the actual image file [which will change whe nthe script is ran]) sounds confusing but I think I can answer questions that you may have.
View Replies !
View Related
Htaccess File Randomly Applied
I have a .htaccess file which sits in the root directory of my site just to switch off those pesky PHPSESSID's. They keep coming back though, particularly when I first reopen the browser and click on the first link. Code: <IfModule mod_php4.c> php_flag session.use_trans_sid off php_value arg_separator.input ;& php_value arg_separator.output ; </IfModule>
View Replies !
View Related
Readdir Randomly Chooses Files
I'm using the usual directory loop script: while(false!== ($file = readdir($fp))){ echo $file; } However, the files are not printed out in order - they come out randomly. In my case, all files are named the same, except they have a timestamp at the end (webcam images, every 5 minutes). So my listing comes out like: img_20070425_0300.jpg, img_20070425_1324.jpg, img_20070425_0127.jpg, etc. I can sort the list after I'm done reading it in. but it's very weird to me why these are coming in randomly (it just started doing this a few days ago, worked fine for months before hand).
View Replies !
View Related
Xml Parsing Problems-->>xml Strings Randomly Cutting Off!
I am working on a project where I am parsing an xml document. The document is converted from a rich text microsoft word document. I'm using this standard parsing method: $xml_parser = xml_parser_create( $type ); xml_set_element_handler($xml_parser, "start_element", "end_element"); xml_set_character_data_handler($xml_parser, "character_data"); When I run the script using this Method, the text will randomly cut off before the xml string has been parsed. For Example: In a list item, the xml code shows: <title><anchor id="Heading107" />1557 Cotton Dr - #3:...............................apartment................1.5 baths Apps, WD conns,carpet, heat pump.............................................................................................$42 5.00</title> the parser breaks it apart and shows this: Cotton Dr - #3:...............................apartment This is driving me crazy and any help would be appreciated.. Thanx All
View Replies !
View Related
Randomly Selecting An Element In An Array That Has Not Been Selected Before..
Im having problems in randomly selecting an element in an array that has not been selected before.. in other words, I have an array of answers to questions, then I want to select 5, with one of them being the correct answer to the question, and the others not.. Here is my code.. (I already have the correct answer at array position [0]) for($i=1;$i<=4;$i++) { //choose a random number in array range $phraseArr_random_answer=rand(1,$phraseArr_size); // check to see if random selection has not already been chosen for($j=0;$j<=$i;$j++) { //check to see if element has already been chosen (j is current array) echo">> ".$answerArr[$j][2] ."<< >>". $phraseArr[$phraseArr_random_answer][2]."<< <br />"; if(strcmp($answerArr[$j][2],$phraseArr[$phraseArr_random_answer][2])) { $alreadyUsed="FALSE"; $i--; //document.writeln("choices[j] = " + choices[j] + " and i = " + i // + " and viet[random_choice] = " + viet[random_choice] + "<br />"); //break; echo"test"; } else { $alreadyUsed="TRUE";/* } } //add a random selection from phraseArr into each element of answerArr if ($alreadyUsed=="TRUE") { $answerArr[$j][2]=$phraseArr[$phraseArr_random_answer][2]; } $answerArr[$i]=$phraseArr[$phraseArr_random_answer][2]; echo $answerArr[$i]." - "; } Thanks to anyone who can tell me the problem with this..
View Replies !
View Related
|