You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try {
// Create connection
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_GET['token'])) {
$encrypted_token = $_GET['token'];
// Fetch exam information from the database based on the encrypted token
$sql_exam = "SELECT e.*, g.group_name
FROM exams e
JOIN exam_groups eg ON e.id = eg.exam_id
JOIN groups g ON eg.group_id = g.id
WHERE MD5(e.id) = :encrypted_token";
if ($exam_data) {
// Exam information
// ... (your existing PHP logic for generating exam information)
} else {
echo "
No exam found for this token.
";
}
} else {
echo "
No token provided.
";
}
if (isset($_GET['token'])) {
$encrypted_token = $_GET['token'];
// Fetch questions and section information from the database based on the exam_id
$sql = "SELECT es.section_name, eq.exam_qno, q.*
FROM exam_questions eq
JOIN questions q ON eq.question_id = q.id
JOIN exam_sections es ON eq.sect_id = es.section_id
WHERE MD5(eq.exam_id) = :encrypted_token";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':encrypted_token', $encrypted_token);
$stmt->execute();
$questions = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Sort the questions based on their exam_qno
usort($questions, function ($a, $b) {
return $a['exam_qno'] - $b['exam_qno'];
});
// Initialize variables to keep track of the current section
$current_section = null;
// Loop through the sorted questions
foreach ($questions as $question) {
$section_name = $question['section_name'];
$question_number = $question['exam_qno'];
// Display section name if it changes
if ($section_name !== $current_section) {
$current_section = $section_name;
echo "
$current_section
";
}
// Fetch question details from the 'questions' table
$question_content = preg_replace('/<p.*?>/', '', $question['question'], 1);
// Apply common style to question content
$question_content = "
$question_content
";
// Display question number and content in a container
echo "
";
echo "
";
echo "
Q$question_number.
";
// Check if passage_id exists in the questions table
if (!empty($question['passage_id'])) {
// Fetch passage from the 'passages' table
$passage_id = $question['passage_id'];
$sql_passage = "SELECT * FROM passages WHERE id = :passage_id";
$stmt_passage = $pdo->prepare($sql_passage);
$stmt_passage->bindParam(':passage_id', $passage_id);
$stmt_passage->execute();
$passage_details = $stmt_passage->fetch(PDO::FETCH_ASSOC);
// Display passage details with corresponding question number
echo "
";
echo "
Passage for Question $question_number: {$passage_details['passage']}
";
echo "
";
}
// Check if the question content is an image
if (strpos($question_content, '<img') !== false) {
// If it's an image, align it properly
echo "
$question_content
";
} else {
// If it's text, align it properly with some spacing to the right
echo "
$question_content
";
}
// Add some spacing between question content and options
echo "
"; // Clear the float to avoid layout issues
echo "
"; // Close question-container div
// Check if the question type is objective (QTYPE_ID = 1)
if ($question['qtype_id'] == 1) {
// Display options as A, B, C, D for objective questions
$options = array($question['option1'], $question['option2'], $question['option3'], $question['option4']);
// Create a table for options with adjusted margin for option labels and content
echo "
";
echo ""; // Start of first table row
foreach (array_slice($options, 0, 2) as $key => $option) {
$option_content = preg_replace('/<p.*?>/', '', $option, 1);
// Create a cell for each option using the provided table structure with less margin for option labels
echo ""; // Cell 1: Option label
echo ""; // Cell 2: Option content
}
echo ""; // End of first table row
echo "
"; // Start of second table row
foreach (array_slice($options, 2) as $key => $option) {
$option_content = preg_replace('/<p.*?>/', '', $option, 1);
// Create a cell for each option using the provided table structure with less margin for option labels
echo ""; // Cell 1: Option label
echo ""; // Cell 2: Option content
}
echo ""; // End of second table row
echo "
" . chr(65 + $key) . ")
$option_content
" . chr(65 + $key + 2) . ")
$option_content
";
}
echo "
"; // Clear the float to avoid layout issues
echo "
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
content in two coloumns with a line in btwen
Author: HARSHVARDHAN (49.37.66.---)
Date: 01-05-24 18:08
i want to achive this code as the content in two columns seprated by line in between please help me
<script type="5e7f1b71d9a8b873404b4887-text/javascript" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJaxec99.js?config=TeX-MML-AM_HTMLorMML"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({extensions: ["tex2jax.js"],jax: ["input/TeX", "output/HTML-CSS"],tex2jax: {inlineMath: [["$", "$"],["\\(", "\\)"]]}}); </script> <style> .masonry { /* Masonry container */ column-count: 2; column-gap: 1em; } .item { /* Masonry bricks or child elements */ display: inline-block; margin: 0 0 1em; width: 100%; } /* Bordered masonry */ .masonry.bordered { column-rule: 1px solid #000; column-gap: 20px; break-inside: avoid; } #foot { display: block; position: fixed; bottom: 8pt; border-top: 1px solid; width: 100%; display:none; } } </style>function encryptExamId($exam_id)
{
// Encrypt the exam_id using MD5 hash
return md5($exam_id);
}
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "new9";
try {
// Create connection
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_GET['token'])) {
$encrypted_token = $_GET['token'];
// Fetch exam information from the database based on the encrypted token
$sql_exam = "SELECT e.*, g.group_name
FROM exams e
JOIN exam_groups eg ON e.id = eg.exam_id
JOIN groups g ON eg.group_id = g.id
WHERE MD5(e.id) = :encrypted_token";
$stmt_exam = $pdo->prepare($sql_exam);
$stmt_exam->bindParam(':encrypted_token', $encrypted_token);
$stmt_exam->execute();
$exam_data = $stmt_exam->fetch(PDO::FETCH_ASSOC);
if ($exam_data) {
// Exam information
// ... (your existing PHP logic for generating exam information)
} else {
echo "
No exam found for this token.
";}
} else {
echo "
No token provided.
";}
if (isset($_GET['token'])) {
$encrypted_token = $_GET['token'];
// Fetch questions and section information from the database based on the exam_id
$sql = "SELECT es.section_name, eq.exam_qno, q.*
FROM exam_questions eq
JOIN questions q ON eq.question_id = q.id
JOIN exam_sections es ON eq.sect_id = es.section_id
WHERE MD5(eq.exam_id) = :encrypted_token";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':encrypted_token', $encrypted_token);
$stmt->execute();
$questions = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Sort the questions based on their exam_qno
usort($questions, function ($a, $b) {
return $a['exam_qno'] - $b['exam_qno'];
});
// Initialize variables to keep track of the current section
$current_section = null;
// Loop through the sorted questions
foreach ($questions as $question) {
$section_name = $question['section_name'];
$question_number = $question['exam_qno'];
// Display section name if it changes
if ($section_name !== $current_section) {
$current_section = $section_name;
echo "
$current_section
";}
// Fetch question details from the 'questions' table
$question_content = preg_replace('/<p.*?>/', '', $question['question'], 1);
// Apply common style to question content
$question_content = "
$question_content
";// Display question number and content in a container
echo "
echo "
echo "
// Check if passage_id exists in the questions table
if (!empty($question['passage_id'])) {
// Fetch passage from the 'passages' table
$passage_id = $question['passage_id'];
$sql_passage = "SELECT * FROM passages WHERE id = :passage_id";
$stmt_passage = $pdo->prepare($sql_passage);
$stmt_passage->bindParam(':passage_id', $passage_id);
$stmt_passage->execute();
$passage_details = $stmt_passage->fetch(PDO::FETCH_ASSOC);
// Display passage details with corresponding question number
echo "
echo "
{$passage_details['passage']}
echo "
}
// Check if the question content is an image
if (strpos($question_content, '<img') !== false) {
// If it's an image, align it properly
echo "
} else {
// If it's text, align it properly with some spacing to the right
echo "
}
// Add some spacing between question content and options
"; // Clear the float to avoid layout issuesecho "
echo "
// Check if the question type is objective (QTYPE_ID = 1)
if ($question['qtype_id'] == 1) {
// Display options as A, B, C, D for objective questions
$options = array($question['option1'], $question['option2'], $question['option3'], $question['option4']);
// Create a table for options with adjusted margin for option labels and content
";echo "
echo ""; // Start of first table row
foreach (array_slice($options, 0, 2) as $key => $option) {
$option_content = preg_replace('/<p.*?>/', '', $option, 1);
// Create a cell for each option using the provided table structure with less margin for option labels
echo ""; // Cell 1: Option label
echo ""; // Cell 2: Option content
}
echo ""; // End of first table row
echo "
"; // Start of second table rowforeach (array_slice($options, 2) as $key => $option) {
$option_content = preg_replace('/<p.*?>/', '', $option, 1);
// Create a cell for each option using the provided table structure with less margin for option labels
echo ""; // Cell 1: Option label
echo ""; // Cell 2: Option content
}
echo ""; // End of second table row
echo "
}
echo "
"; // Clear the float to avoid layout issuesecho "
}
} else {
echo "
No token provided.
";}
// Generate PDF using mpdf
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Beta Was this translation helpful? Give feedback.
All reactions