List Records In Random Order
I got 10 records from mysql database, i know that it can list with ORDER BY name , time whatever.
does anyone know how to list them in random order, so that anyone can have a chance to list at the top (first item) etc.
View Complete Forum Thread with Replies
Related Forum Messages:
Return Records In Random Order
I have a table which stores details of businesses. I want to know if it is possible using MySQL to generate random results sets. For example suppose there are a total of 30 rows returned from a query, can MySQL randomly generate the order that these 30 results are ordered or will it always return them in the same order?
View Replies !
Random Order
How would you make a randomizer where you pick 6 words and it randomizes them in order so that no word is repeated?
View Replies !
Custom Order For Records...
I have a simple Content Management System where the site owner can enter information about projects they have been involved in. The CMS writes these to separate rows in a MySQL5 table. The user wants to be able to choose the order that the projects are displayed in, so that his favourite projects can be at the top of the list. Does anyone know how to do this? Ideally I'd like to let him move items up and down the list or to the top or bottom of the list.
View Replies !
Order My Random Array
Can i select a specific order (not a sort but a particular order) rather than this random order that is generated (and returned by $new_arr) in the code:
View Replies !
While Loop Random Order
can you order the out put of a while loop randomly? so one time it will show table values: 1 5 6 3 8 9 and next time it might show 5 7 3 2 8 1 etc... Is it possible??
View Replies !
Rotating In Order, Not Random
I'm using a small script that randomly rotates words/html through a single line from a text file. I'm trying to rotate the list in order so the next refresh would go down the list. <? $textfile ="qoutes.txt"; $items = file("$textfile"); $item = rand(0, sizeof($items)-1); echo $items[$item]; ?>
View Replies !
Order By Random With Pagination
I am trying to ramdomize the results so that everyone has a chance of being on the first page, but I don't know how to hold it after the first page, when I click on page 2, it randomizes the results again, and puts some of the ones on the first page on the second. Is there a way around this: Code:
View Replies !
Show The First 30 Records In Reverse Order
I have a table like this: +-----------+-----------------------+ | item id | item | +-----------+-----------------------+ | 1 | blah1 | | 2 | blah2 | | 3 | blah3 | | 4 | blah4 | +-----------+-----------------------+ Awful diagram, sorry. Anyways, say this table goes on for, say, 60 records. Now, how do I show the first 30 records in reverse order. So, it would look like this: blah30 blah29 blah28 blah27 blah26 blah25 etc. until it reached blah1. How do I do this?
View Replies !
Returns The Records In Primary Key Order.
I have a table containing customers which has a primary key on a field called "customerid". I have the following query: SELECT DISTINCTROW priority, customerid FROM tblcustomers WHERE customerid IN (10153,609,156,663,10128) The query works but always returns the records in primary key order. I want the order in the order specified using the IN keyword as above. Is this possible with MySQL?
View Replies !
Selecting A Mysql Row Set In A Random Order
I have implemented a links bar on the side of a site, which I want to popuplate with links from a database randomly, but I feel the php workaround I used is inefficient. Is there a way to randomize the result in a mysql SELECT query? "SELECT * FROM links ORDER random" I know the code above is probably way off, but it illustrates what I want I think.
View Replies !
'random' Order Of Radio Buttons
Does anyone have a good idea how to make the order that radio buttons appear on a page 'random'. I have a form for a quiz that has five radio buttons with one correct answer and four incorrect answers against them. The answers are pulled from my database and at the minute all come through in the same order (i.e. where I put them against the 'value') so when the user submits and the next question, with its answers, are pulled from the database they are in the same order as the previous answers.
View Replies !
Put Three Random Variables In Order, Lowest To Highest...
I was interested in how I can order these variables in order, lowest to highest... $number1 = rand(1, 6); $number2 = rand(1, 6); $number3 = rand(1, 6); This is like rolling three dice and then ordering them like 1, 2, 3, or 1, 3, 5, etc. I want to echo them out in whatever order is lowest to highest.
View Replies !
Retrieve Array Subset In Random Order
Anyone have a clever way to retrieve for example, items 0-29 from an array of size N>29, in random order? The catch is that I dont want to print any items more than once and I dont want to miss any. This is for a tag cloud where I have sorted them by popularity but now I need to display only the top 30. I do this now but they are in order of popularity and its not really a 'cloud'. If I could retrieve the top 30 in some random order, it would look better.
View Replies !
Selecting Random Records
I want to select a record from the table in random fashion. Like $myrand=rand(1,25); select * from faltu where bekar='$myrand' but here the problems is that rand() returns repeated values. So I used srand() but still the repetition is there. I have 50 records in the table and want to select only 25 of that one at a time. How do I do it.
View Replies !
Random Unique REcords From SQL
I'm trying to create a page that retreives up to 15 random records out of an SQL table to be displayed to a user, at the same time, they cannot be duplicates. I dont quite know how to go about doing this effectivly. One method i was trying to use included nesting a while loop in a for loop to determine if each record retreived has a unique ID, but that led to a dead end with infinite loops.
View Replies !
How Could I Print Random Date On Set Of Records
How can i get random date on each record which i show from a table. To explain in detail: I'll show 20 records from a table, the first 7 records shld have todays date and the next 4 records yesterdays date and 8 records day after yesterday and so on until the end of record set.
View Replies !
Random Order Help Request - Prevent Previously Displayed Objects
I have a query that is showing new items in a store based upon their inventory date. The problem with my Random order sort is that when the "next" link is pressed, the random function is called again and I may see the image previously displayed rather than go through the entire new inventory. SELECT * FROM `Catalog` WHERE (`Catalog`.thumbnail LIKE '%-04.%' or `Catalog`.thumbnail LIKE '%-05.%' or`Catalog`.thumbnail LIKE '%-03.%' ) and `Catalog`.img_status = Ƈ' and `Catalog`.views != Ɔ' ORDER BY RAND()
View Replies !
Dynamic List Order
I was trying to get the list box to display the id numbers in ascending order however the code below does not work, just wondering how to fix it? <?php $g = "SELECT * FROM em ORDER BY iD ASC"; $q = mysql_query($g, $link_id) or die(mysql_error()); if (mysql_num_rows($q) > 0) { ?> <select name="d"> <?php while($r = mysql_fetch_assoc($q)) { ?> <option value="<?php echo $r['Id']; ?>"><?php echo $r['Id']; ?></option> <?php } } ?>
View Replies !
List Results In Certain Order
I was wondering if their is a more efficient way to write the code below. It lists the results ($id and $url) in the order of $link[1] then $link[2] then $link[3]. The trick is I only want to use the 1 select statement Code:
View Replies !
User Selected Order Of List
My experience in php and mysql is just copying and pasting freebie scripts- very limited. I'm wanting to create or better yet find another freebie script which will in my real estate site on the page with a table listing properties with headings such as date/ type/beds/baths/price etc. users be able to click on a heading which will then list the properties according to the selected heading, so if they choose 'type', the page will refresh and show all houses or land or apartments according to type grouped together and so on. First I think I need to have a link on the heading buttons to activate a php script which will send info to mysql database and if the database is configured right through the admin area it will respond accordingly. But what php script? How complicated could it be?
View Replies !
? Updating Sort Order For Complete List
I've been working on building a content management system that will allow you to also create/maintain your navigation. Part of that includes sorting your navigation. I want to be able to have graphical links that will allow you to push an item up or down in the sort order, while updating the rest of the table data with their new sort value. For example, let's say I've got three items in my nav table: sort name ------------------ 1 cat 2 dog 3 fish I want to be able to have a link that will, say for example, move "fish" to the number two spot and automatically update dog to a sort value of "3" and have all of this updated in MySQL. I've searched through various PHP script sites and tutorials to clue me in on what I need to do to pull this off, but I haven't found anything. Is there a way to assign new values to multiple table rows and have that information stored accordingly?
View Replies !
Selection Of Records In List
I was wondering how to query MySQL to display only a selection (1-20, 21-40) of a query in an HTML list. Can that be done in an SQL statement, or do you have to use PHP to dissect the returned array with for n elements to n+20 elements. How does Google achieve the returning of results in its search engine. I imagine that the same query may not necessarily be executed each page listing. I am wondering whether the results from the query would return an array of say 36000 elements.
View Replies !
Random Link List?
Does anyone know of an easy way to turn a hard coded list of links (these links are <a href='something'><img...) into a random display?? most likely triggered by the page refresh.
View Replies !
SQL Syntax To Update Records With Diff'rent Function Generated Random PINS
I use a function, myrandomPIN (), to generate random PIN numbers. The following sql query updates records with the SAME PIN number but. I want to generate DIFFERENT pin numbers for every record. The function is ok but I can't figure out how to run it individually for each record. In other words I do not know the correct syntax to use UPDATE in a loop (if necessary) so that a different call to the function is done every time or ecah record ends up with a different PIN. Or may be this can be done with a single mysql_query($sql2)? -------------------------------------------------------------------------- $qr = @mysql_query($sqlb1) or die("ERROR"); $rs1 = mysql_fetch_array($qr); $thepin=myrandomPIN(); $sql2="UPDATE clients SET pin='$thepin' WHERE code='".$thecode."'"; $qr = @mysql_query($sql2) or die("ERROR""); --------------------------------------------------------------------------
View Replies !
Multiple Delete From A List Of Records
If I have a list of records from a database on the screen, each with a check box beside them, how would I delete all the records that have been ticked? I assume I would use a variable similar to checked[], but not sure what syntax I would use to remove them from the database? Would I loop round each record comparing the checked[] value and it it's set, delete the record?
View Replies !
List Filenames In Descending Numerical Order, But Also Ascending Alphabetical
I am trying to write a script that lists the filenames in a directory in descending numerical order, followed by ascending alphabetical order. For example, I have the following filenames in a directory: 20070317_Pear.jpg 20070421_Kiwi.jpg 20070423_Grape.jpg 20070519_Apple.jpg 20070519_Banana.jpg 20070519_Orange.jpg My desired list order is: 20070519_Apple.jpg 20070519_Banana.jpg 20070519_Orange.jpg 20070423_Grape.jpg 20070421_Kiwi.jpg 20070317_Pear.jpg So, within a group of files that begin with the same number, I'd like the files to sort in ascending order by alphabet, rather than descending order. Here's the code I've attempted. It sorts numerical in descending order, but won't sort alphabetically in ascending order: Code:
View Replies !
Generate A Random List Within My HTML
I'm trying to generate a random list within my HTML. I've done random lists before, but this is giving me problems. In the code below, $file should be printing the array I have stored in $file. $file contains raw HTML, comprised of about 10 items right now, but will be higher as I add to it. (That is why I did the $arraycount). I did a var_dump($file) and I can see that $file does indeed contain what I want it to, but I just cannot get the contents into my page. Code:
View Replies !
Choose Random Item From List But With Different Weighting
I want to choose an item at random, but have different probabilities for each item. One easy way is just to create an array like $a[]=1 $a[]=2 $a[]=3 $a[]=3 That way a random number between 1 and 4 would give the weighting I want, but it seems like there has to be a much smarter way to do this. I've seen some algorithms for random distributions, but they don't quite do what I want. Oh yeah - must not require a DB; this should work with values from a CSV or similar ...
View Replies !
Adding ID To Random Link Pulled From List With Php Script
I'm using script which pulls random url from list with links and loads it, but I want my affiliated webmasters to be able to add their ID to these links. for example: I'm calling the script with: mydomain.com/thescript.php and it pulls link from the list called links.txt so I want my webmaster to be able to add their id at the end of mydomain.com/thescript.php and this ID to be added to the random loaded link from the list (links.txt)
View Replies !
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 !
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 !
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 !
List Contents Of A Folder, Make List Of Links
Does anyone know how I can write a script that: - reads in all the files in a particular directory - displays the file names in a html list and makes a link of them: <ul> <li><a href="filelocation1">filename 1</li> <li><a href="filelocation2">filename 1</li> <li><a href="filelocation3">filename 1</li> </ul> etc.? So basically it creates a list of links with the contents in that directory, so you can download them from there.
View Replies !
Get List Of Messages From One Table, Message List Indicator From
I have two tables. One has a list of messages left by users using fields named mbxno for the mailbox and msgno for the message number. I have another table that has mailbox settings for each user that contains a field named "messagelist" to indicate if they want to be included on the message list or not. What I'm trying to create is a list of the most-recent messages with a lookup on the users table to indicate whether a message in the list should be included in the message list based on the user's mailbox settings. SELECT messages.msgno, messages.mbxno, users.messagelist FROM messages, users WHERE (users.messagelist = Ƈ') ORDER BY msgno DESC LIMIT 100 What I'm getting, though is a list that looks like this: mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 1114 msgno: 0412141623 msglist: 1 I think what's happening is that I'm using the wrong type of join and more rows are being created than necessary. If I add "DISTINCT" to the query, I get a list of the most-recent messages as I expect, but the "messsagelist" value is sometimes wrong (again, probably because the data is getting jumbled). For example, the messagelist value for the second row (2214) should be 0, not 1. mbxno: 1114 msgno: 0412141623 msglist: 1 mbxno: 2214 msgno: 0412141622 msglist: 1 mbxno: 2189 msgno: 0412141408 msglist: 1 mbxno: 0000 msgno: 0412141213 msglist: 1 mbxno: 0003 msgno: 0412141213 msglist: 1 mbxno: 2265 msgno: 0412132029 msglist: 1 mbxno: 0000 msgno: 0412131950 msglist: 1 How should I be doing this? If nothing else, what kind of join will work with a long list compared to a value from a short list?
View Replies !
Mailing List Manager, Send To List
I'm looking for a mailing list script (php) that has a function to let users to reach out to all recipient on the list by simple send the email to a specific maillist- address. Mailman has this functionn but as a just got a webserver account I can't use mailman nor install it.
View Replies !
List Dir / List Files
Is there a fast way to read files/directory recursively? Instead of inspecting each file(s)/dir(s), is there a way to know that its a file or a directory from its hidden attribut both for windows or unix filesystem?
View Replies !
List To Populate Another List
i have a form with 3 dropdown list. the first is for a canditate, 2nd is for party, 3rd is for state and 4th is for the local areas in the state. I want if the user selects a state, the dropdown list for the local area to be populated automatically. But since they are on the same form i am not sure how.here is my code <td><select name="state" tabindex="3"> <?php #this is to get listing for roles in a drop dowm menu #the sql query $sql1 = "SELECT distinct(state_name) FROM state order by state_name "; #execute query $rs1 = mysql_query($sql1, $myConn) or die ("could not execute query $sql"); if ($rs1){ while ($row1 = mysql_fetch_array ($rs1)){ echo("<option>" . $row1['state_name'] . "</option>"); } } ......................
View Replies !
Order By...
Is it possible to sort of like order by one field and then if they are equal values on that field then you order by another field...: ORDER by club AND ORDER by whatever Would that work?
View Replies !
If...else - In Which Order
this is probably an old topic: if(a==1) if(b==2) echo "a is 1 and b is 2"; else // what happens here? echo "a is 1 and b is not 2"; The question is, where the else will react too. Usually it should be the last if. In general I put {} around just to be sure.
View Replies !
Add A Second ORDER BY
Currently I have "ORDER BY name ASC" - can I add a second ORDER BY in there? I tried "ORDER BY package DESC AND name ASC" but it did not work.
View Replies !
SQL Order
I have done a basic query: Code: select d, f from acc where cId= $_session cd; So far when using this query with php it displays the data in the order it was entered which is what I want but I was wondering will it always do this or will i need some form of order by?
View Replies !
|