Jump to content

Barand

Moderators
  • Posts

    24,481
  • Joined

  • Last visited

  • Days Won

    814

Barand last won the day on August 12

Barand had the most liked content!

About Barand

Profile Information

Recent Profile Visitors

99,646 profile views

Barand's Achievements

Prolific Member

Prolific Member (5/5)

2.1k

Reputation

485

Community Answers

  1. Perhaps... $a = explode(',', '1.1.51,1.1.51.10,1.1.51.2,1.1.51.3,1.1.51.4,A,1.1.52'); echo 'original <pre> ' . print_r($a, 1) . '</pre>'; sort($a); echo 'after sort() <pre> ' . print_r($a, 1) . '</pre>'; natsort($a); echo 'after natsort() <pre> ' . print_r($a, 1) . '</pre>'; giving... original Array ( [0] => 1.1.51 [1] => 1.1.51.10 [2] => 1.1.51.2 [3] => 1.1.51.3 [4] => 1.1.51.4 [5] => A [6] => 1.1.52 ) after sort() Array ( [0] => 1.1.51 [1] => 1.1.51.10 [2] => 1.1.51.2 [3] => 1.1.51.3 [4] => 1.1.51.4 [5] => 1.1.52 [6] => A ) after natsort() Array ( [0] => 1.1.51 [2] => 1.1.51.2 [3] => 1.1.51.3 [4] => 1.1.51.4 [1] => 1.1.51.10 [5] => 1.1.52 [6] => A )
  2. Try a ... <html> <head> </head> <body> </body> </html> ... structure instead of your pick'n'mix approach to the documant sections. (And why was this posted in PHP Coding Help forum?)
  3. I'd start by checking what data contains with console.log(data)
  4. To add a listener to an element, the element must exist. Make sure you add the listeners after the elements have been created.
  5. That's the thing about programming - it does what you tell it to do. You told it to respond to clicks inside the div. Try document.getElementByTagName("input").addEventListener("click", displayDate); function displayDate() { alert('Hurray'); }
  6. As you have it now but make the <select> required (to force a values other than "") <select name="cars" id="cars" required> <option value="" >Car choices</option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </select>
  7. Judicious application of array key names can greatly increase the efficiency and simplicity of your code. Consider this simplified version of the questions/options form code <form method='post' > <?php for ($qno=1; $qno<=2; $qno++) { echo <<<HTML <label> Sub Question $qno <span class="req">*</span> <textarea cols="46" rows="3" name="Q[$qno][question]" placeholder="Enter Sub question here.."></textarea> </label> <ul> HTML; for ($opt='A'; $opt<='D'; $opt++) { echo <<<HTML <li>Choice $qno$opt (text)&nbsp; <input type='text' name="Q[$qno][opts][$opt]" placeholder="Enter Choice A here.." size='40'> </li><br><br>\n HTML; } echo "</ul><hr>\n"; } ?> <input type='submit'> </form> producing... When the form is submitted, the POST array is like this... Array ( [Q] => Array ( [1] => Array ( [question] => aaaaaaaaaaaaaaaaaaaaaaaaaaa [opts] => Array ( [A] => aa [B] => bb [C] => cc [D] => dd ) ) [2] => Array ( [question] => bbbbbbbbbbbbbbbbbbbbbbbbb [opts] => Array ( [A] => ww [B] => xx [C] => yy [D] => zz ) ) ) ) Now you can easily iterate through the array to write the questions/options to you database foreach ( $_POST['Q'] as $qno => $qdata ) { write $qno and $qdata['question'] to question table save last insert id as $qid foreach ( $qdata['opts'] as $ono => $choice ) { write $qid, $ono, $choice to choice table } } Job Done.
  8. Almost 5,000 chars of unformatted html! TLDR
  9. Use join() instead of the foreach loop. echo join(':', $numbers);
  10. Let me introduce you to the reference manual. See https://www.php.net/mysqli_fetch_array
  11. mysqli_fetch_array() does not return the number of rows To do that you would need to remove and authorized ='1' and add "authorized" to the selected columns. Then check if $num['authorized'] == 1 (or not).
×
×
  • 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.