Jump to content

stephflix

Members
  • Posts

    14
  • Joined

  • Last visited

stephflix's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm not trying to store an image to a database. I'm trying to take the image from the database and put in on my website through PHP.
  2. Maybe seeing the entire code might help.... <?php // connect to database require_once('includes/mysqli_connect_northwind.php'); ?> <?php //get our parameters // condition ? true value : false value $sort = isset($_GET['sort']) ? $_GET['sort'] : "CategoryName"; $dir = isset($_GET['dir']) ? $_GET['dir'] : "ASC"; // our query to select categories $query = "SELECT * FROM categories ORDER BY $sort $dir"; // execute our query $result = @mysqli_query($dbc, $query) or die('Error in query: ' . mysqli_error($dbc)); // sort directions $cat_dir = ($sort == "CategoryName" and $dir == "ASC") ? "DESC" : "ASC"; $desc_dir = ($sort == "Description" and $dir == "ASC") ? "DESC" : "ASC"; $pic_dir = ($sort == "Picture" and $dir == "ASC") ? "DESC" : "ASC"; // loop through results echo '<table> <thead> <tr> <td><a href="?sort=CategoryName&dir='.$cat_dir.'">Category Name</a></td> <td><a href="?sort=Description&dir='.$desc_dir.'">Description</a></td> <td><a href="?sort=Picture&dir='.$pic_dir.'">Picture</a></td> </tr> </thead> <tbody>'; // loop through the results while( $row = mysqli_fetch_array($result) ){ // $row represents the current record in the database //echo '<pre>'; //print_r($row); //echo '</pre>'; // $row['ColumnName'] echo '<tr> <td><a href="products2.php?CategoryName=' . $row['CategoryName'] . '"> ' . $row['CategoryName'] . ' </a></td> <td>' . $row['Description'] . '</td> <td>' . $row['Picture'] . '</td> </tr>'; } echo '</tbody> </table>'; // close connection to database mysqli_close($dbc); ?>
  3. I was wondering if there is a image format code is get images from a database to show up. For example I use: <td>' . number_format($row['Population']) . '</td> the number_format to fix the population to show up the way I want. Is there an image format? Or what do I do? Right now it's showing up as a long string of text. <td>' . $row['Picture'] . '</td> Thanks in Advance!!
  4. Ugh, i see it now. Thanks. I wish I could figure this stuff out...grrrr.
  5. <link href="Style/style.css" rel="stylesheet" type="text/css" /> <?php $page_title = "Pitch Perfect"; ?> <?php include_once('includes/header.php'); ?> <div class="content"> <?php echo '<h1>Are you Aca-Awesome?</h1>'; $quiz_questions = array(); $quiz_questions['q1'] = array( 'question' => 'What is Rebel Wilsons Character Name?', 'choices' => array( 'a' => 'Fat Amy', 'b' => 'Rebelicious', 'c' => 'Fat Samy', 'd' => 'Pitch Slapper'), 'answer' => 'a'); $quiz_questions['q2'] = array( 'question' => 'What are Nodes?', 'choices' => array( 'a' => 'An STD', 'b' => 'Vocal cords rubbing together at an above average rate w/o proper lubrication', 'c' => 'A point at which lines or pathways intersect', 'd' => 'A high note'), 'answer' => 'b'); $quiz_questions['q3'] = array( 'question' => 'What song did Beca audition with?', 'choices' => array( 'a' => 'Cups', 'b' => 'Call me Maybe', 'c' => 'Titanium', 'd' => 'No Diggity'), 'answer' => 'a'); $quiz_questions['q4'] = array( 'question' => 'Where does Beca work?', 'choices' => array( 'a' => 'Jamba Juice', 'b' => 'Vocal coach at the university', 'c' => 'University radio station', 'd' => 'McDonalds'), 'answer' => 'c'); $quiz_questions['q5'] = array( 'question' => 'What happened at last years finals?', 'choices' => array( 'a' => 'They Won', 'b' => 'Chloe had surgery on her vocal chords', 'c' => 'Bumper sabotaged the Barden Belles', 'd' => 'Aubrey threw up on stage'), 'answer' => 'd'); $total_answered = 0; $total_correct = 0; if($user_answers[$qid] ==' '){ //user did not answer the question }elseif($user_answers[$qid] == $question['answer']){ //answer is correct $total_answered++; $total_correct++; }else{ //answer is wrong $total_answered++; } foreach ($quiz_questions as $qid => $q_data) { echo '<br><strong>' . $q_data['question'] . '</strong><br>'; echo "<input type='hidden' name='answer[$qid]' value='{$q_data['answer']}'>"; echo "<input type='hidden' name='choice[$qid' value='' />"; //in case no selection foreach ($q_data['choices'] as $cid => $choice) { echo "<input type='radio' name='choice[$qid]' value='$cid' /> $choice<br>"; } } echo '<p align="center"><input type="submit" name="submit" value="Submit" /></p>'; ?> </div> <?php include_once('includes/footer.php'); ?> Does anyone know why I'm getting the following errors and how I can fix them? Undefined variable: qid Undefined variable: user_answers Line 61 & 63
  6. Thank you so much Barand! You've been a HUGE help!
  7. That worked! But how do I make it display radio buttons?
  8. <?php $quiz_questions = array(); $quiz_questions['q1'] = array( 'question' => 'What is Rebel Wilsons Character Name?', 'choices' => array( 'a' => 'Fat Amy', 'b' => 'Rebelicious', 'c' => 'Fat Samy', 'd' => 'Pitch Slapper'), 'answer' => 'a'); $quiz_questions['q2'] = array( 'question' => 'What are Nodes?', 'choices' => array( 'a' => 'An STD', 'b' => 'Vocal cords rubbing together at an above average rate w/o proper lubrication', 'c' => 'A point at which lines or pathways intersect', 'd' => 'A high note'), 'answer' => 'b'); $quiz_questions['q3'] = array( 'question' => 'What song did Beca audition with?', 'choices' => array( 'a' => 'Cups', 'b' => 'Call me Maybe', 'c' => 'Titanium', 'd' => 'No Diggity'), 'answer' => 'a'); $quiz_questions['q4'] = array( 'question' => 'Where does Beca work?', 'choices' => array( 'a' => 'Jamba Juice', 'b' => 'Vocal coach at the university', 'c' => 'University radio station', 'd' => 'McDonalds'), 'answer' => 'c'); $quiz_questions['q5'] = array( 'question' => 'What happened at last years finals?', 'choices' => array( 'a' => 'They Won', 'b' => 'Chloe had surgery on her vocal chords', 'c' => 'Bumper sabotaged the Barden Belles', 'd' => 'Aubrey threw up on stage'), 'answer' => 'd'); if($user_answers[$qid] ==' '){ //user did not answer the question }elseif($user_answers[$qid] == $question['answer']){ //answer is correct $total_answered++; $total_correct++; }else{ //answer is wrong $total_answered++; } foreach($quiz_questions as $qid => $question){ //output the question text echo '<p>'.$question['question']. '<p>'; } foreach($question['choices'] as $cid => $choice){ $lid = $qid.'_'.$cid; //default message $msg = ' '; $checked = ($user_answers[$qid]== $cid) ? ' checked ' : ' '; //if all questions have been answered, display correct and wrong answers if($total_answered > 0 and $total_answered == $total_questions){ if ($checked){ if($user_answers[$qid]== $question['answer']){ $msg = echo '<p>CORRECT!</p>'; }else{ $msg = echo '<p>INCORRECT</p>'; } } } echo ' <input type="radio" name=" ' . $qid . ' " value= " ' .$cid. ' " id= " ' .$lid. ' " ' . $checked . '/> <label for =" '. $lid . ' ">' . $choice . '</label>'; ?>
  9. Hey Everyone, I'm trying to make a quiz in PHP for a class. THis is what I have so far. I just can't get the answers to show up. Any help will be wonderful! <?php $quiz_questions = array(); $quiz_questions['q1'] = array( 'question' => 'What is Rebel Wilsons Character Name?', 'choices' => array( 'a' => 'Fat Amy', 'b' => 'Rebelicious', 'c' => 'Fat Samy', 'd' => 'Pitch Slapper'), 'answer' => 'a'); $quiz_questions['q2'] = array( 'question' => 'What are Nodes?', 'choices' => array( 'a' => 'An STD', 'b' => 'Vocal cords rubbing together at an above average rate w/o proper lubrication', 'c' => 'A point at which lines or pathways intersect', 'd' => 'A high note'), 'answer' => 'b'); $quiz_questions['q3'] = array( 'question' => 'What song did Beca audition with?', 'choices' => array( 'a' => 'Cups', 'b' => 'Call me Maybe', 'c' => 'Titanium', 'd' => 'No Diggity'), 'answer' => 'a'); $quiz_questions['q4'] = array( 'question' => 'Where does Beca work?', 'choices' => array( 'a' => 'Jamba Juice', 'b' => 'Vocal coach at the university', 'c' => 'University radio station', 'd' => 'McDonalds'), 'answer' => 'c'); $quiz_questions['q5'] = array( 'question' => 'What happened at last years finals?', 'choices' => array( 'a' => 'They Won', 'b' => 'Chloe had surgery on her vocal chords', 'c' => 'Bumper sabotaged the Barden Belles', 'd' => 'Aubrey threw up on stage'), 'answer' => 'd'); if($user_answers[$qid] ==' '){ //user did not answer the question }elseif($user_answers[$qid] == $question['answer']){ //answer is correct $total_answered++; $total_correct++; }else{ //answer is wrong $total_answered++; } foreach($quiz_questions as $qid => $question){ //output the question text echo '<p>'.$question['question']. '<p>'; } foreach($question['choices'] as $cid => $choice){ $lid = $qid.'_'.$cid; //default message $msg = ' '; $checked = ($user_answers[$qid]== $cid) ? ' checked ' : ' '; //if all questions have been answered, display correct and wrong answers if($total_answered > 0 and $total_answered == $total_questions){ if ($checked){ if($user_answers[$qid]== $question['answer']){ $msg = echo '<p>CORRECT!</p>'; }else{ $msg = echo '<p>INCORRECT</p>'; } } } echo ' <input type="radio" name=" ' . $qid . ' " value= " ' .$cid. ' " id= " ' .$lid. ' " ' . $checked . '/> <label for =" '. $lid . ' ">' . $choice . '</label>'; ?>
  10. Ok, here's what I have now: $questionarray = array( "What is Rebel Wilsons Character Name?" => array ( 20 => "Fat Amy", 0 => "Rebelicious", 0 => "Fat Samy", 0 => "Pitch Slapper", ), "What are Nodes?" => array ( 0 => "An STD", 20 => "Vocal cords rubbing together at an above average rate w/o proper lubrication", 0 => "A point at which lines or pathways intersect", 0 => "A high note" ), "What song did Beca audition with?" => array ( 20 => "Cups", 0 => "Call me Maybe", 0 => "Titanium", 0 => "No Diggity" ), "What happened at last years finals?" => array ( 0 => "They Won", 0 => "Chloe had surgery on her vocal chords", 0 => "Bumper sabotaged the Barden Belles", 20 => "Aubrey threw up on stage" ) ); // $questionarray is the key and $options is the value (an array) foreach ($questionarray as $questions => $options) { echo '<p>'; echo $questions; echo '<br>'; // $options is the key and $points is the value foreach ($options as $answer => $points) { echo '<input type="radio" name="questions" value="20" id="questions" />'; echo $answer; echo '<br>'; } echo '</p>'; } echo '<p align="center"><input type="submit" name="submit" value="Submit" /></p>'; It displays my quiz but it only allows me to answer one of the questions. When I click on the radio button for question 2 it erases question 1.
  11. Hi Jessica, That's completely understandable. You are correct, this is a homework assignment that I've been working on for some time. I just really don't understand it. Here's what I have so far: <?php $questions = array("Rebel Wilson's Character Name","What are Nodes?","What was Fat Amy's Secret Truth?", "What song did Beca audition with?", "What happened at last years finals?"); $answers = array( array(0 =>'Fat Amy','Rebelicious','Fat Samy','Pitch Slapper'), array(0 => 'Vocal cords rubbing together at an above average rate w/o proper lubrication','An STD','A high note','A point at which lines or pathways intersect'), array(0 => 'My real name is Fat Patricia','I cheated on my boyfriends',"I'm kind of a stalker",'Back at my old school I was already a star'), array(0 => 'Cup Song','Call me Maybe',"Titanium",'No Diggity'), array(0 => 'Aubrey threw up on stage','They Won',"Chloe had surgery on her vocal chords",'Bumber sabotaged the Barden Belles') ); function shuffle_assoc(&$array) { $keys = array_rand($array, count($array)); foreach($keys as $key) $new[$key] = $array[$key]; $array = $new; return true; } I just really don't understand how to use a foreach loop to display the questions and choices. Is there anything you can do to help me?
  12. Does anyone know how to do this? Use one multi- dimensional associative array to store the questions, choices and answers for this quiz. Use a nested foreach loop to display the questions and choices. Create and use a simple function to calculate the percentage based on the number correct out of the total number of questions.
×
×
  • 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.