-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
As you want to sort on the first element of each array then all you should need is sort($menu);
-
If you have all the questions on one page then name your radio buttons something like "answer[$id]" where $id is the id of the question. Then if you answer B for Q1, C for Q2 and D for Q3 then $_POST['answer'] will look like this when you come to process the results array ( 1 => 'B' 2 => 'C' 3 => 'D' ) All you need to do then is get the correct answers from the database for each question and compare. Here's an example <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'dbname'); $correct = array(); /************************************************ * if answers posted, check them *************************************************/ if ($_SERVER['REQUEST_METHOD']=='POST') { $sql = "SELECT question_no , correct_answer FROM quiz_questions"; $res = $db->query($sql); while ($row = $res->fetch_assoc()) { $correct[$row['question_no']] = $row['correct_answer']; } // get the posted answers and compare aginst correct ones $total = 0; if (isset($_POST['answer'])) foreach ($_POST['answer'] as $qno => $ans) { if ($ans == $correct[$qno]) { $total++; } } echo "You got $total answers correct<br>"; } $sql = "SELECT question_no , question , answerA , answerB , answerC , answerD FROM quiz_questions ORDER BY question_no"; $output = ''; $res = $db->query($sql); while (list($qno,$q, $a, $b, $c, $d) = $res->fetch_row()) { $output .= "<div class='wrapper'> <div class='question'>$qno. $q</div> <div class='answers'> <input type='radio' name='answer[$qno]' value='A'>$a<br> <input type='radio' name='answer[$qno]' value='B'>$b<br> <input type='radio' name='answer[$qno]' value='C'>$c<br> <input type='radio' name='answer[$qno]' value='D'>$d<br> </div> <div style='clear:both'></div> </div>"; } ?> <html> <head> <title>Quiz</title> <style type='text/css'> div { font-family: sans-serif; font-size: 10pt; } .wrapper { border-bottom: 2px solid gray; padding: 5px; margin-bottom: 5px; height: auto; } .question { width: 40%; float: left; } .answers { width: 60%; float: left; } </style> </head> <body> <h3>Quiz</h3> <form method='post' action=''> <?=$output?> <input type='submit' name='btnSubmit' value='Results'> </form> </body> </html> It would be a better design to have your answers in a separate table, each row containing question_id || option value || answer_text
-
Put the date values inside single quotes, mysql> select 2015-09-03 as A, '2015-09-03' as B; +------+------------+ | A | B | +------+------------+ | 2003 | 2015-09-03 | +------+------------+ otherwise SQL thinks it is 2015 minus 9 minus 3
-
Does it help if you change <?=$trows?> to <?php echo $trows; ?>
-
therefore those are the columns you need to JOIN SELECT c.id , c.desc , c.identity , d.defect FROM character_defects c LEFT JOIN defects d ON c.defect = d.id WHERE c.identity = 'Sailor Moon'
-
If your php version < 5.4 change [] to array() in those lines.
-
How to get form nested in while loop to work?
Barand replied to innovatio's topic in PHP Coding Help
My suggestion also included putting the hidden field, containing the id, inside the form. -
Datetime functions differ greatly between sqlsrv and mysql. I'd start by looking there. Check sqlsrv_error array after calling the query
-
Good evening - Money waiting for support on updating a function please
Barand replied to sorn53's topic in PHP Coding Help
You don't even need to write a script - a single update query will do it. Add a new DATETIME column (eg 'newdate') to the table to store the new date first. UPDATE dbb SET newdate = STR_TO_DATE(expiredate, '%m-%d-%Y-%H:%i') -
Getting mysql data to work with array script.
Barand replied to xwishmasterx's topic in PHP Coding Help
try $conn = new mysqli(HOST,USERNAME,PASSWORD,'test'); $data = array(); $sql = "SELECT date, a, b FROM mytable"; $res = $conn->query($sql); while (list($date, $a, $b) = $res->fetch_row()) { $data['A'][] = array($date, $a); $data['B'][] = array($date, $b); } -
How to get form nested in while loop to work?
Barand replied to innovatio's topic in PHP Coding Help
You have two <form> tags, one at the start of the loop and another just before the submit buttom. Suggest you put the hidden id field after the second and remove the first. -
<?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); $newarray = [11=>[],12=>[],1=>[],2=>[],3=>[],4=>[],5=>[],6=>[],7=>[],8=>[],9=>[],10=>[]]; $data = []; $trows = ''; /********************************************************** * store data in array by course ***********************************************************/ $sql = "SELECT c.cid , c.courseName , e.startDate , MONTH(e.startDate) as month FROM course c LEFT JOIN eventtbl e USING (cid) ORDER BY cid,startDate"; $res = $db->query($sql); while (list($cid, $cn, $sd, $m) = $res->fetch_row()) { if (!isset($data[$cid])) { $data[$cid]['name'] = $cn; $data[$cid]['events'] = $newarray; } if ($sd) $data[$cid]['events'][$m][] = date('j/m/Y', strtotime($sd)); } /********************************************************** * create table from array data ***********************************************************/ foreach ($data as $cid=>$cdata) { $trows .= "<tr><td>$cid</td><td class='cn'>{$cdata['name']}</td>"; foreach ($cdata['events'] as $dates) { $trows .= "<td class='dt'>" . join('<br>', $dates) . "</td>"; } $trows .= "</tr>\n"; } ?> <html> <head> <title>Example</title> </head> <style type='text/css'> table { border-collapse: collapse; } tr { vertical-align: top; } td, th { font-family: sans-serif; font-size: 9pt; padding: 3px; } td.cn { width: 120px; } td.dt { width: 70px; text-align: right; } </style> <body> <table border='1'> <tr> <th rowspan='2'>Course</th> <th rowspan='2'>Course Name</th> <th colspan='3'>Q1</th> <th colspan='3'>Q2</th> <th colspan='3'>Q3</th> <th colspan='3'>Q4</th> </tr> <tr> <th>November</th><th>December</th><th>January</th> <th>February</th><th>March</th><th>April</th> <th>May</th><th>June</th><th>July</th> <th>August</th><th>September</th><th>October</th> </tr> <?=$trows?> </table> </body> </html>
-
Good evening - Money waiting for support on updating a function please
Barand replied to sorn53's topic in PHP Coding Help
As I told you, that format doesn't work, echo date('Y-m-d H:i:s', strtotime("06-09-2015-12:00")) //---> 2015-09-06 13:00:00 which is why I suggested DateTime::createFromFormat('m-d-Y-H:i', $expiredate); -
Good evening - Money waiting for support on updating a function please
Barand replied to sorn53's topic in PHP Coding Help
You should always store datetimes in a DB as type DATETIME, format YYYY-MM-DD HH:MM:SS. Other formats are largely useless. For now, if you are stuck with that "-" you can $expiredate = "06-09-2015-12:00"; $dtobj = DateTime::createFromFormat('m-d-Y-H:i', $expiredate); $expiretime = $dtobj->getTimestamp(); -
Good evening - Money waiting for support on updating a function please
Barand replied to sorn53's topic in PHP Coding Help
why the weird datetime format? If that is m-d-y format then just losing the "-" between date and time will work without the preg_replace()s $expiredate = "06-09-2015 12:00"; $expiretime = strtotime($expiredate); -
You think? How much testing did you do? mysqli_num_rows() returns a number (which may be 0) and not a boolean true/false result mysqli_error() tales the $conn object as its parameter, not the result object. getting no records returned is not an error, so there would be no message to echo in that event. You need to take a look in the manual more often.
-
There may be confusion here between basename() and dirname() $dir = " /home/public_html/folder_here/another_folder"; echo basename($dir).'<br>'; //--> another_folder echo dirname($dir).'<br>'; //--> /home/public_html/folder_here
-
There is no universal "correct" way. It all depends on your specific needs.
-
What file? There is no mention of files in your code. By "previous" do you mean the folder that the file was in before being moved to its current location?
-
SELECT GROUP_CONCAT(NULLIF(Other_type, 'All_other') as projtype2, ...
-
try <table border="1"> <tr><th>Rate</th><th>Annual Interest</th><th>Monthly Interest</th></tr> <?php $amount = 50000; for ($i=1; $i<=10; $i++) { $rate = $i/100; $annual = '$' . number_format($amount * $rate, 2); $month = '$' . number_format($amount * $rate / 12, 2); echo "<tr><td>{$i}%</td><td>$annual</td><td>$month</td></tr>"; } ?> </table>
-
There is a solution to similar problem here http://forums.phpfreaks.com/topic/298003-data-display-in-wrong-column/?do=findComment&comment=1520058