Jump to content

Selecting Particular Multiple Rows


kwdelre

Recommended Posts

I am running a query to get a certain student's quiz results from all attempts and print one after the other in a simple table for now. The student is designated by an email address. I need results from all of the rows containing this particular email. The issue I think I am having is that when I use "WHERE" and specify an email address that exists many times in the table it isn't storing the variable correctly. Here is code below that I cannot get working right.

 

When I try to print these variables as a test to see if they are working I get nothing. No errors either. I have checked all names, spellings, and capitalization about 5 times. Thanks for looking at it.

 

$QuizQuery = mysql_query("SELECT * FROM Quiz_Results WHERE Email = '".$_SESSION['UserEmail']."' AND Quiz_Name = 'M1'")
or die(mysql_error());

$i=1;

while ($QuizResults = mysql_fetch_array($QuizQuery)){

$UserEmail = $QuizResults['Email'];
$Score = $QuizResults['Score'];
$Date = $QuizResults['Date_Taken'];


echo "<table width='650' border='1'><tr><td>";
echo "Attempt #".$i."<br></td><td>Score: ".$Score."</td><td>";
if($QuizResults['Pass'] == "PASSED"){
echo "Passed";
}
else {
echo "Failed";
}
echo "</td><td>Date Taken: ".$Date."</td></tr></table>";



$i++;
}

Link to comment
Share on other sites

...When I try to print these variables as a test to see if they are working I get nothing...

 

what exactly do you meen by that? if you do

printr($_SESSION['UserEmail']);

nothing appears or that the page is just black, or that there is nothing that looks like an error being shown and everything apears to be ok?

 

Also, could you please show where your session variables are being assigned, as this could be relevant is the information is being passed in wrongly (<- is that even a word? :shrug: ).

A short sample dataset from the table would help a lot too.

Link to comment
Share on other sites

When I use print_r() I get nothing. The page loads with no data displayed. Here is the full code. Thanks for looking.

 

mysql data fields = Id, Quiz_Id (PRI, AUTOINC), Quiz_Name, Score, Pass, Date_Taken

 

<?
include('db.php');
session_set_cookie_params(1200);
session_start();
if(ISSET($_POST['Email'])){
$_SESSION['UserEmail'] = $_POST['Email'];
}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="ptdetxquiz.css" type="text/css" rel="stylesheet" />
</head>
<style type="text/css">

body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background-color: #fff;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
</style>
<body>
<div class="oneColFixCtr">
<div id="container">
<img src='images/backgroundtop.jpg' />
<div id='container2' align='center'>
<img src="images/quizrecordsbanner.jpg" />

<?
//Change DB Selected
mysql_connect($host, $dbusername, $password);
mysql_select_db($TxQuizdb);

$VerifyQuery = mysql_query("SELECT Email, Stud_First_Name, Stud_Last_Name FROM ".$RegTable." WHERE  Email = '".$_SESSION['UserEmail']."' ")
or die(mysql_error());
$Verify = mysql_fetch_array($VerifyQuery);
$_SESSION['StudFirstName'] = $Verify['Stud_First_Name'];
$_SESSION['StudLastName'] = $Verify['Stud_Last_Name'];




if(($Verify)){




echo "<br><br><br><div id='summarytitle'>".$_SESSION['StudFirstName']." ".$_SESSION['StudLastName']."'s Quiz Records:</div>";
echo "Module 1 Quizzes<br>";


$QuizQuery = mysql_query("SELECT * FROM Quiz_Results WHERE Email = '".$_SESSION['UserEmail']."' AND Quiz_Name = 'M1'")
or die(mysql_error());

$i=1;

while ($QuizResults = mysql_fetch_array($QuizQuery)){

$UserEmail = $QuizResults['Email'];
$Score = $QuizResults['Score'];
$Date = $QuizResults['Date_Taken'];


echo "<table width='650' border='1'><tr><td>";
echo "Attempt #".$i."<br></td><td>Score: ".$Score."</td><td>";
if($QuizResults['Pass'] == "PASSED"){
echo "Passed";
}
else {
echo "Failed";
}
echo "</td><td>Date Taken: ".$Date."</td></tr></table>";



$i++;
}
print_r($UserEmail);
echo $i;
print_r($Score);
print_r($QuizResults['Email']);
//echo $QuizResults['Email'];












}
else{
echo "E-mail address not found. Please re-enter your e-mail.<br><form action='myquizzes.php' method='post' />
<input type='text' size='40' name='Email' /><br />
<input type='submit' name='submit' value='View Quiz Records' />";
}
?>


</div>
<img src="images/backgroundbottom.jpg" />
</div>


</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.