0

I have a email script that sends out information from the mysql database with the following code, but it only sends out one name and ID, but in the email it should send all 20 names and IDs. My question how can I get this fix and working right. Thanks for any help.

//retreive questions from database and put into question box
$query2 = "SELECT `studentID`,`studentName` FROM `quiz1question`";

$question2 = mysql_query($query2);
 while($row = mysql_fetch_array($question2)){

$studentName = $row['studentName'];
$studentID = $row['studentID'];

$msg .= '<p>Student Name: '.$studentName.' or Student ID: '.$studentID.'</p>';


// ------------------------------------------------------------

$to = "cc-wp@hotmail.com";

$subject = "CT-80 Quiz/Test Results";

$from = "akamerc@hotmail.com";

$headers ="From: $from\n";

$headers .= "MIME-Version: 1.0\n";

$headers .= "Content-type: text/html; charset=iso-8859-1 \n";

if(mail($to,$subject,$msg,$headers)) {

    echo "success";

    exit();

} else {       

    echo "failed";

    exit();

}
?>

<?php } ?>
2
Contributors
9
Replies
11
Views
4 Years
Discussion Span
Last Post by mikelopez77
0

Thanks for the reply what I am trying to do is this in the email. Database has 20 name or whatever. In the email should look like this with the following info:

  1. **
  2. **
  3. **

and so on. It just shows 1.** and thats it. when I take out exit(); it sends me mass emails.

0

Thanks for the help again and also it works. Here's the result.

//retreive questions from database and put into question box
$query2 = "SELECT * FROM `quiz1question` `student`";

$question2 = mysql_query($query2);
 while($row = mysql_fetch_array($question2)){

$id = $row['id'];
$question = $row['question'];
$quizAnswer = $row['quizAnswer'];
$aee = $row['aee'];
$bee = $row['bee'];
$cee = $row['cee'];
$dee = $row['dee'];
$studentName = $row['studentName'];
$studentID = $row['studentID'];

$msg .= 'Student Name: '.$studentName.' <br />Student ID: '.$studentID.' <br />'.$id.' '.$question.' <br />A. '.$aee.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />B. '.$bee.'&nbsp;&nbsp;&nbsp;&nbsp;<br />C. '.$cee.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />D. '.$dee.'<br />Your Answer:<br />
Correct Answer: '.$quizAnswer.'<br /><br />';

?>
<?php } ?>
<?PHP
// ------------------------------------------------------------

$to = "cc-wp@hotmail.com";

$subject = "CT-80 Quiz/Test Results";

$from = "akamerc@hotmail.com";

$headers ="From: $from\n";

$headers .= "MIME-Version: 1.0\n";

$headers .= "Content-type: text/html; charset=iso-8859-1 \n";

if(mail($to,$subject,$msg,$headers)) {

    echo "success";

    exit();

} else {       

    echo "failed";

    exit();

}
?>
0

In my email it looks like this, but how can I get it to just show the Student Name and Student Id only on the top and not on all of it like its doing on nubmer 2.

Student Name: 
Student ID: 
1 Whats black and white? 
A. AAA        
B. dd    
C. dsds            
D. cop car
Your Answer:
Correct Answer: cop car

Student Name: 
Student ID: 
2 What process determines the identity of a user? 
A. AAA        
B. dsdsd    
C. DDD            
D. cccc
Your Answer:
Correct Answer: cccc
0

Sorry but I am lost now. How would I write a if statement and where would I put it.

0

I think this looks wrong.

if ( $studentName == "studentName" )
   {
echo "Student Name: '$studentName'";
$msg .= ''.$id.'.  '.$question.' <br />A. '.$aee.'        <br />B. '.$bee.'    <br />C. '.$cee.'            <br />D. '.$dee.'<br />Your Answer:<br />
Correct Answer: '.$quizAnswer.'<br /><br />';
 }

Trying to get it like this

 Student Name: 

    1. Whats black and white? 
    A. AAA        
    B. dd    
    C. dsds            
    D. cop car
    Your Answer:
    Correct Answer: cop car

    2. What process determines the identity of a user? 
    A. AAA        
    B. dsdsd    
    C. DDD            
    D. cccc
    Your Answer:
    Correct Answer: cccc

and not like this

Student Name: 

1. Whats black and white? 
A. AAA        
B. dd    
C. dsds            
D. cop car
Your Answer:
Correct Answer: cop car

Student Name: 

2. What process determines the identity of a user? 
A. AAA        
B. dsdsd    
C. DDD            
D. cccc
Your Answer:
Correct Answer: cccc

Edited by mikelopez77: added more info

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.