Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Random Query from DB without repeating
Old 07-11-2010, 12:25 PM Random Query from DB without repeating
Junior Talker

Posts: 3
Trades: 0
Hi to You all! I'm having some problems with getting query from database, here's the script:

PHP Code:
$qProfile "SELECT * FROM cg_riddles WHERE status = 1 ORDER BY RAND() LIMIT 1  "
As u can see, it takes one random entry (let's say it's a question) from DB, in next part of the script user have input form where he's posting answer.

What do i want to do is: if user answer is right, he's getting next question, but i need to do something, that the question won't repeat.

I was thinkin about coockies, then session, but i'm kind a php newbie, and there's a problem. i was trying with:

PHP Code:
$_SESSION[ids]=array(); 
array_push($_SESSION[ids],$id); 
but that ain't workin well, that ain't workin at all :P.

My question: what's the best way to do what i want to do? Mayve string? Any ideas? And maybe links to something i could read that help me?

[sorry for my english]
andrzej_ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-11-2010, 12:36 PM Re: Random Query from DB without repeating
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.titov.net/2005/09/21/do-n...ws-from-table/
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-11-2010, 12:48 PM Re: Random Query from DB without repeating
Junior Talker

Posts: 3
Trades: 0
thank you chrishirst, thanks to that link i'll change my query .

also have idea, how to do rest, can i store informations like $id in session? and adding next after user answer is good?
andrzej_ is offline
Reply With Quote
View Public Profile
 
Old 07-11-2010, 02:05 PM Re: Random Query from DB without repeating
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
can i store informations like $id in session?
That wont be a problem.

Quote:
and adding next after user answer is good?
Don't quite understand, but if that means storing the correct answer in the session as well to save querying the DB again, yes it is.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-11-2010, 02:36 PM Re: Random Query from DB without repeating
Junior Talker

Posts: 3
Trades: 0
Quote:
Originally Posted by chrishirst View Post
That wont be a problem.

Don't quite understand, but if that means storing the correct answer in the session as well to save querying the DB again, yes it is.

I've done it this way:

PHP Code:
        if (isset($_COOKIE['CookieName'])) {
        
$oldid $_COOKIE['CookieName'];
        
$cookie_content "$id";          
        
setcookie("CookieName""$oldid $cookie_content"time()+172800);        
        }
        else {
        
$cookie_content "$id";    
        
setcookie("CookieName"$cookie_contenttime()+172800);
        } 
Thanks for help .
andrzej_ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Random Query from DB without repeating
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15193 seconds with 12 queries