SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    query with date function

    Hello,

    I am working on quiz. Each day i want to show one quiz according to the schedule(today's date). But i want to show this quiz till Monday to Friday. according to 1 days interval i am showing previous days result. But got stuck when Friday comes because i want to show Fridays result on Monday not on Saturday. so can anyone tell me how can i do that.

    here is my code.

    PHP Code:
    <?
    $sql  
    ="SELECT * FROM schedule where start_date = date(now()) AND quiz_id like '%FIB%'";
    $sql_result=mysql_query($sql) or die(mysql_error());
    if(
    mysql_num_rows($sql_result) > 0)
    {
       while(
    $row mysql_fetch_array($sql_result))
       {
          
    $quizid=$row['quiz_id'];
          
    //echo "$quizid";
       
    }?>
        <h4>Fill in the blanks</h4>
        <p class="desc1">Select the correct option.<br/>Score: 1 Point for the correct answer.</p>
       <?

    $query
    mysql_query"SELECT * FROM fillintheblank WHERE quizid='$quizid'");

               if(
    mysql_num_rows($query) > 0){
             while(
    $row mysql_fetch_assoc($query)){ ?>
    <form action="<?$PHP_SELF;?>"  method="post">

         <table style='font:12px Verdana, Arial, sans-serif; padding: 0 0 20px 0;'>
         <tr>
         <td style='padding: 20px 0 10px 0; line-height:20px;'><b>Q.</b> <?=$row['question'];?> </td>
         </tr><tr><td>
         <?
           $options
    =$row['answer'];
           
    $string                   explode(",",$options);
           
    $total_count=count($string);
           
    //echo "$total_count"; ?>


              <?   for($i=0;$i<$total_count;$i++)
                 { 
    ?>

    <input type="radio" value="<?php echo $string[$i]; ?>" name="answer"> <?php echo $string[$i];?>
    <br/>

           <?php
             
    }
    // End while loop.?>

        </td>
         </tr>
         <tr><td><br/>
         <input class="submit" type="submit" name="submit" value="submit">
         </td></tr>
         </table>

        <input type ="hidden" value="<?php echo $row['quizid']; ?>" name="quizid">
        <input type ="hidden" value="<?php echo $row['correct_answer']; ?>" name="correct_answer">
       <p>&nbsp;</p><p>&nbsp;</p>
        </form>

     <?}}}

    // this gives me link to see the previous days result.
     
    $querymysql_query("SELECT * FROM schedule WHERE (quiz_id like '%FIB%' AND start_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 1 DAY))");
                 if(
    mysql_num_rows($query) > 0)
                 {
                   while(
    $row mysql_fetch_array($query))
                   {
                      
    $quiz_id=$row['quiz_id'];
                      
    //echo "$quiz_id";
                      
    $start_date=$row['start_date'];
                      
    //echo "$start_date";
                   
    }
                 }
                 else
                 {
                 }
    mysql_free_result($query);

    ?>
    So my question is how can i check with my query if it is Friday the n show that days quiz result on Monday?

    Thanks in advance

  2. #2
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to do something like this for my previous days quiz answer.

    if its not Friday then

    Code:
    $query= mysql_query("SELECT * FROM schedule WHERE (quiz_id like '&#37;FIB%' AND start_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 1 DAY))");
    if its monday, show Friday's quiz result like this
    Code:
    $query= mysql_query("SELECT * FROM schedule WHERE (quiz_id like '%FIB%' AND start_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 2 DAY))");
    How can i check whether it is Friday or how can i show my Friday quiz result on Monday not on Saturday.

  3. #3
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    <?php
      $weekday = date('w');
      switch($weekday){
        case '1':
              //it's monday, show the recored of last friday
              $sql = $query= mysql_query("SELECT * FROM schedule WHERE (quiz_id like '%FIB%' AND start_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 3 DAY))");
              break;
        case '0':
        case '6':
              //it's weekends, don't show anything
              break;
        default:
              //previous day's record
              $query= mysql_query("SELECT * FROM schedule WHERE (quiz_id like '%FIB%' AND start_date = DATE_SUB(CONCAT(CURDATE(), ' 00:00:00'), INTERVAL 1 DAY))");          
              break;    
      }
    ?>

  4. #4
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for you help.

    Its working.

    I never thought i can do something like this also. Today you taught me really something new.

    Thanks a lot
    SitePoints rocks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •