Page 1 of 1

need some help with retrieving and displaying data

Posted: Tue Apr 20, 2010 1:03 pm
by wjarrett
[text]I have set up a online course and testing module for my students using Moodle (similar to blackboard)
There is a daily question (one for each day of the year).
The user logs in , goes to a screen that shows the user a calendar.
A php script runs which checks which dates the student has completed.
If they have done that day, I want an X to be inserted into the cell for that day.

An example of the php script is included below. Php is still new to me so I could be violating some rule or something
but I have gone round and round and cant seem to find what I am doing wrong.

I have been going at this problem for about a week now and seem to be getting hung up on something I'm missing.
I've flipped through the manual and google enough times to recognize I'm just going in circles around the answer that should probably
be self evident by now but I can't seem to see the forest through the trees....
{/text]

Code: Select all


<?php

   require_once("../../config.php");
   require_once("locallib.php");


//Force the user to login if he already has not done so

   require_login($course->id, false, $cm);


function Checker($arg)
{

include '../../mydbconfigdata.inc';

  $con = mysqli_connect($host, $user, $password, $dbname') or die (mysql_error());
  $sql = "SELECT * 
  FROM mdl_quiz_attempts
  INNER JOIN mdl_quiz 
  ON mdl_quiz.id = mdl_quiz_attempts.quiz 
  WHERE mdl_quiz_attempts.userid = $USER->id 
  AND mdl_quiz_attempts.sumgrades = 1 
  ORDER BY mdl_quiz_attempts.quiz";


echo $arg;

$result = mysqli_query($con,$sql) or die(mysql_error());

        if (mysqli_num_rows($result))
              {
               While ($row=mysqli_fetch_row($result))
                    {
                     if (stristr($row[11], $arg))
                         {
                         echo "X";
                         }
                    }
               }
        else
              {
              echo 'No Data Available';
              }
}

?>

<html>
<head></head>
<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>

<div class=Section1>

<p class=MsoNormal align=right style='text-align:right'><i style='mso-bidi-font-style:normal'><span style='font-size:14.0pt;color:blue'>



<?php
echo "You are logged in as ", $USER->firstname, " ", $USER->lastname;
?>


<o:p></o:p></span></i></p>

/////// more html to create a calendar here...........................................


///////Skip down to January 1


///////Cell for Jan 1
<span style='mso-bookmark:OLE_LINK1'></span>
<td nowrap valign=bottom style='border-top:none;border-left:none;border-bottom:
  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-bottom-alt:
  solid windowtext .5pt;mso-border-right-alt:solid windowtext .5pt;background:
  #CCCCFF;padding:.75pt .75pt 0in .75pt;height:4.15pt'
  onclick="window.location.href='http://www.mywebsite.com/moodle/mod/quiz/attempt.php?id=396'">
  <p class=MsoNormal style='margin:0in;margin-bottom:.0001pt'><span
  style='mso-bookmark:OLE_LINK1'>

<?php
//Calls the function Checker to put an x in Jan 1 box if question has been answered.
echo Checker(1);
?>

<o:p></o:p></span></p>
</td>


///////Cell for Jan 2
<span style='mso-bookmark:OLE_LINK1'></span>
<td nowrap valign=bottom style='border-top:none;border-left:none;border-bottom:
  solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-bottom-alt:
  solid windowtext .5pt;mso-border-right-alt:solid windowtext .5pt;background:
  #CCCCFF;padding:.75pt .75pt 0in .75pt;height:4.15pt'
  onclick="window.location.href='http://www.mywebsite.com/moodle/mod/quiz/attempt.php?id=397'">
  <p class=MsoNormal style='margin:0in;margin-bottom:.0001pt'><span
  style='mso-bookmark:OLE_LINK1'>

<?php
//Calls the function Checker to put an x in Jan 2 box if question has been answered.
echo Checker(2);
?>

<o:p></o:p></span></p>
</td>



///////etc, etc, etc. until done with calendar.


</body>

</html>

:banghead:

Re: need some help with retrieving and displaying data

Posted: Fri Apr 23, 2010 7:05 pm
by mecha_godzilla
Assuming you haven't fixed this already, where you have the following section of code, near the top

Code: Select all

$con = mysqli_connect($host, $user, $password, $dbname') or die (mysql_error());
  $sql = "SELECT *
  FROM mdl_quiz_attempts
  INNER JOIN mdl_quiz
  ON mdl_quiz.id = mdl_quiz_attempts.quiz
  WHERE mdl_quiz_attempts.userid = $USER->id
  AND mdl_quiz_attempts.sumgrades = 1
  ORDER BY mdl_quiz_attempts.quiz";
you've got an extra apostrophe in the mysqli_connect() function - this isn't required but because it's there PHP thinks you're trying to include a value that needs to be parsed and then assumes that the rest of the script (up until it sees another apostrophe) is the value (IE maximum breakage!) If you haven't got one already, you really need a text editor that supports coloured syntax highlighting - I normally use BBEdit (as I'm on a Mac) but ConTEXT is also worth looking at if you've got a PC, otherwise try gedit for Linux. This kind of thing is so common that syntax highlighting is a must or you'll waste your life away looking for that rogue ; ' or ).

HTH,

Mecha Godzilla