Jump to content

Barand

Moderators
  • Posts

    24,529
  • Joined

  • Last visited

  • Days Won

    820

Everything posted by Barand

  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).
  12. To do this you would use a SQL query to match A's preferences against B's profile and return all matching Bs To do this you would use a SQL query to match A's profile against B's preferences to see if A can view B
  13. Check phpinfo() output to ensure you are editing the php.ini file that is actually being used. If it is the right one, check you really have the extension file and in the right folder. edit... PS Check you have PDO available - you'll be better off using that than mysqli.
  14. Example: My customer table contains these columns Columnss ------------- syncroid State Postcode id CompanyName City Address and I want to exclude id and syncroid from the dropdown list. <?php $res = $pdo->query("SELECT column_name FROM information_schema.Columns WHERE table_schema = 'db1' AND table_name = 'customer' ORDER BY column_name DESC"); $result = $res->fetchAll(PDO::FETCH_COLUMN); // define unwanted column names $exclude = ['id', 'syncroid']; // remove them $columns = array_diff($result, $exclude); ?> <select name='up_column' id='up_column'> <?php foreach ($columns as $col) { echo "<option>$col</option>\n"; } ?> </select> DROPDOWN...
  15. Once your page hits the browser there is nothing php can do. Any further client-side processing will require javascript. When page has loaded, set a timer ( see setTimeout() ) to initiate a process which hides your loading bar.
  16. You have already left it too long, but the longer you put it off the worse it will get. There are definite advantages to upgrading with new features having been added (both in PHP 8 and MySQL 8). The downside is your database processing will need to change. I'd also strongly recommend you use PDO rather than switching to mysqli (There is more involved than just adding an "I" to the function calls). How much extra coding will need changing will depend on how you coded in the past. For example, PHP8 is stricter on variable typing. EG <?php $a = ''; $b = 5; echo $a + $b; You probably get away with that at the moment , the '' being silently converted to '0', but with v8 you get PHP Fatal error: Uncaught TypeError: Unsupported operand types: string + int in C:\inetpub\wwwroot\test.php:4 Note that $a = '0' will work as it is convertible to int 0.
  17. First, click on the error notification and sort out the error. Then try again.
  18. Select "Developer tools" in browser menu Open network tab. Instigate the AJAX request When ajax call appears in network window, click on it Select response tab to response or request tab to see request
  19. Have you checked your network responses in your browser's developr tools?
  20. Unchecked checkboxes are not posted. I prefer to use a the null coalescing operator (??) when handling checkboxes EG $Bold = $_POST['Bold'] ?? 0; //if not set, default to '0'
  21. See https://www.php.net/manual/en/features.file-upload.php
×
×
  • 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.