#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Preston,Lancashire,United Kingdom
    Posts
    1
    Rep Power
    0
    I'm very close to completing a quiz site, all the questions are held in one table, with various categories such as Pop Music, Trivia etc. My select statement selects all the questions in one category, then from these a random question is shown.

    My problem is the fact that quite often the same question gets shown twice or even three times.

    Is it possible to have a select statement with more than one condition, so for example
    select ID from questions WHERE Category1 = '$Category1' AND $ID != '342' AND $ID != '247'

    When I try this I get errors and no data returned at all, can anybody help with this ??
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    You were checking if a field $ID wasn't 342 or 247 I am assuming your field is called ID and thus should be setup like so

    select ID from questions WHERE Category1 = '$Category1' AND ID != '342' AND ID != '247'
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Preston,Lancashire,United Kingdom
    Posts
    1
    Rep Power
    0

    That's fixed it !! Thanks for the prompt reply, I spent hours messing with that !!

    You're a genius !!

    Graham
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    35
    Rep Power
    14
    why not try this:

    You create the rand number out side the database, so, you can use cookie or session to store a set of asked question_id , the script will like that:

    #get the total number of questions
    $qid = mysql_query("select count(*) from...");
    $fetch_result = mysql_fetch_row($qid);
    $int_total_question_number = $fetch_result[0];

    #generate the rand number
    do{
    $select_question_id = rand(0,$int_total_question_number-1);
    while ( $select_question_id in setof{asked question id} )

    #show the question
    select qusetion from questions WHERE Category1 = '$Category1' and id='$seelct_question_id'
    show_question();

    #put the select_question_id into set
    put_into_set($select_question_id);

    that is just syntax,
    hope to help


    ------------------
    Good Good Study
    Day Day Up

Similar Threads

  1. Using sessions for search / results pages
    By Quirk in forum PHP Development
    Replies: 10
    Last Post: December 15th, 2003, 08:36 PM
  2. excluding certain results in query
    By jules00 in forum MySQL Help
    Replies: 2
    Last Post: November 25th, 2003, 05:35 PM
  3. Limit results on 'left join' query
    By tippiedog in forum MySQL Help
    Replies: 1
    Last Post: November 12th, 2003, 07:58 AM
  4. Replies: 3
    Last Post: August 27th, 2003, 04:26 PM
  5. search results coming from multiple tables
    By frostfire in forum MySQL Help
    Replies: 0
    Last Post: August 12th, 2003, 09:23 AM

IMN logo majestic logo threadwatch logo seochat tools logo