TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-29-2010, 06:40 PM   #1 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default How to get random number based on the condition.

i have two table in my database which is the room table and roomtype table.i'm using phpmyadmin.

room table
room_no
r_roomtypeID


roomtype table
roomtypeID
roomtype


how can i create a query that can select A random room_no from "room table "
based on the roomtypeID in the "table roomtype"

p/s - each roomtypeID got it's own quantity room no.

roomtypeID room_no

example : Single room : 1-10
: Deluxe room : 11-20
: Suite room : 21-30

right now i'm only having this kind of idea. the random number from room. I don't know how can i generate A random room_no from table room based on the roomtypeID.
Code:
(SELECT room_no FROM room ORDER BY RAND( )LIMIT 1)
fairytale89 is offline  
Reply With Quote
Old 03-29-2010, 07:12 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Here is one way that comes to mind (adapt the select statement to your needs:
SQL Code:
SELECT *, RAND() AS orderByMe FROM tableName WHERE 1 ORDER BY orderByMe LIMIT 1
__________________

Village Idiot is offline  
Reply With Quote
Old 03-31-2010, 04:15 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Did this method work?
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
fairytale89 (04-02-2010)
Old 04-02-2010, 02:08 AM   #4 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default

yeah..it did really work. I already tried it ...
thanks:)
fairytale89 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
To write a condition based on time? sandhyagupta Absolute Beginners 0 07-14-2009 09:46 AM
Unique random number? code_junkie Advanced PHP Programming 4 12-21-2008 12:01 AM
Showing random links with an array paulOr Advanced PHP Programming 6 10-24-2008 09:28 AM
Flat file array, replace 3rd key value based on itself. Peuplarchie Absolute Beginners 1 07-22-2008 12:38 AM
How Rdoanm is Rondam? Wildhoney General 3 09-19-2007 01:32 PM


All times are GMT. The time now is 07:23 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design