General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 14th, 2002, 10:10 AM
ozzie ozzie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: London
Posts: 11 ozzie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Inserting New questions

Got a small problem, been trying to figure out the best way of tackling this.

What I'm trying to do is when a user deletes 2 questions from the quiz, there are "gaps" left in the quiz.

For example

Question Num
1
3
5
6
7
8
So in this case question 2 is missing and question 4 is missing

I've written some code to accommodate this, however when the user enters 2 questions again then it inserts into table questions 2 and 3 which it should fill the gap
with question 4 instead, because question 3 has been filled.

I know this may sound complicated....but heres the code

PHP Code:
# theres query to print random questions, which then inserts
# them into array.
while (list($DBqsid2)=mysql_fetch_row($result1))
{
                                                     
$DBqsids2[]=$DBqsid2;
                                              } 


PHP Code:
 $result=mysql_query("select number from quiz_questions_map
                          where quiz_questions_map.qzid=
$qzid
                          order by number"
);
     
$number=0;
     
$found=0;
     while ((list(
$DBnumber)=mysql_fetch_row($result)) && $found==0)
     {
       if (
$number==$DBnumber 1)
       {
         
$number=$DBnumber;
       }
       else
       {
         
$found=1;
# the problem rises here
#$DBqids2 is an array of questions so it goes thru the
# array and inserts into the table but it will insert 3 into            
# the number field which already exists
         
$num=count($DBqsids2);
         for (
$x=0;$x<$num;$x++)
         {
           
$number+=1;
           echo 
"INSERT into quiz_questions_map (qzid,qsid,number)
               VALUES (
$qzid,".$DBqsids2[$x].",$number)";
           
#mysql_query("INSERT into quiz_questions_map (qzid,qsid,number)
           #VALUES ($qzid,".$DBqsids2[$n].",$number)");
         
}
       }
 
     } 


PHP Code:
# this bit finds if there no gaps in the quiz, and appends to the
# end of the quiz accordingly, this works well indeed!!
if ($found==0)
     {
       
$num=count($DBqsids2);
       for (
$n=0;$n<$num;$n++)
       {
         
$number+=1;
         echo 
"INSERT into quiz_questions_map (qzid,qsid,number)
                               VALUES (
$qzid,".$DBqsids2[$n].",$number)";
         
#mysql_query("INSERT into quiz_questions_map (qzid,qsid,number)
         #             VALUES ($qzid,".$DBqsids2[$n].",$number)");
       
}
     } 


I hope you have digested all that, I'll let you know if I have suitable solution.

Thanks all.......

Ozzie

Reply With Quote
  #2  
Old May 15th, 2002, 01:10 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Hi Ozzie.
Hmmmm. Is it 100% necessary to have sequential numbers for each question. Maybe have one primary key unique id field, and have another called questionNumber and make that sequential...therefore when a question is deleted, you can just update questionNumber and not worry about unique id's, etc...

Or you could just put a sortKey field in and order by that to set the questions into their correct order every time?

Reply With Quote
  #3  
Old May 15th, 2002, 05:20 AM
ozzie ozzie is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: London
Posts: 11 ozzie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

Cheers mytch,

It is necessary to have sequential numbers for each question. But I know there is a way to insert questions to fill in "blank" slots in the quiz.

As you see in my code theres a query which selects the question numbers order by number, then perhaps compare the number from the database with a counter variable and insert the question number accordingly..

Perhaps that way could be the best solution...

Thanks

Ozzie

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Inserting New questions


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap