kwdelre Posted January 20, 2011 Share Posted January 20, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/225056-selecting-particular-multiple-rows/ Share on other sites More sharing options...
Muddy_Funster Posted January 20, 2011 Share Posted January 20, 2011 ...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? ). A short sample dataset from the table would help a lot too. Quote Link to comment https://forums.phpfreaks.com/topic/225056-selecting-particular-multiple-rows/#findComment-1162401 Share on other sites More sharing options...
kwdelre Posted January 20, 2011 Author Share Posted January 20, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/225056-selecting-particular-multiple-rows/#findComment-1162594 Share on other sites More sharing options...
kwdelre Posted January 20, 2011 Author Share Posted January 20, 2011 Forgot to say, session variables in this code work fine. Its just the first couple lines in my original post that do not work. This is the only variable working in that section print_r($UserEmail); Quote Link to comment https://forums.phpfreaks.com/topic/225056-selecting-particular-multiple-rows/#findComment-1162606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.