Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I am not sure just how a cron job can be secured. Any security features may need to be within the functions themselves or the data.
  2. Seems like you want eight cron jobs (four for each job) that run on the same date every year.
  3. Get a decent editor! Four errors found... Unwanted single quote Mispelled and unwanted "</label>" Mispelled and unwanted "</label>" Missing "a" at start of "<a .... "
  4. This example will repopulate the category menu depending on the selected type <html> <head> <title>Sample</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> // array of categories for each type var cat_types = JSON.parse('{"A":{"1":"Cat 1","2":"Cat 2","3":"Cat 3"},"B":{"4":"Cat 4","5":"Cat 5","6":"Cat 6"},"C":{"7":"Cat 7","8":"Cat 8","9":"Cat 9"}}'); $().ready(function() { // populate type menu $.each(cat_types, function(k,v) { $("#type").append($("<option>", {"val":k, "text":k})) }) // when type selected, populate cat menu $("#type").change( function() { $("#cat").html("<option value=''> - select category -</option"); var type = $(this).val() $.each(cat_types[type], function(k, v) { $("#cat").append($("<option>", {"val":k, "text":v})) }) }) }) </script> <style type='text/css'> </style> </head> <body> <form> Type <select name='type' id='type'> <option value=""> - select type -</option> </select> <br><br> Cat <select name='cat' id='cat'></select><br> </form> </body> </html>
  5. To do pagination successfully you need to know the total number of pages. That means a query at the start to count the number of rows. You are correct in using SELECT COUNT(*), however using mysql_num_rows after that query will always return "1" as the query will return a single row containing the count. All you need to do is read the count column value returned. $res = $conn->query("SELECT COUNT(*) FROM table1"); // get the count $total_recs = $res->fetch_row()[0]; // read the first column of the returned row You would use the query with LIMIT clause once you know which page to get.
  6. Or avoid the concatenation which is usually the biggest source of error (and the query string needs an "=") echo "<a href='icerik.php?icerik={$goster['icerik_id']}'>{$goster['baslik']}</a>";
  7. @ginerjm has just told you what's wrong.
  8. For completeness, I should state that an alternative method to the above is to use fetch() Here is an alternative script section using fetch instead of $.get() <script type='text/javascript'> $().ready( function() { $("#find").click( function() { var tid = $("#tid").val() fetch('?ajax=teacher&tid='+tid) .then(response => response.json()) .then(data => handleOutput(data)) }) }) function handleOutput(resp) { $.each(resp, function(k,v) { $("#"+k).val(v) }) } </script>
  9. Something like this? <?php $data = " <Message> <EntityType>Document</EntityType> <ProductSETS> <Entity> <id>1</id> <Specification1>Name</Specification1> <Specification2>Color</Specification2> <Specification3>Type</Specification3> <Specification4>Manufacturer</Specification4> <Price>Product Price</Price> </Entity> <Entity> <id>100</id> <Specification1>Car model 1</Specification1> <Specification2>Red</Specification2> <Specification3>Hybrid car</Specification3> <Specification4>Telsa</Specification4> <Price>10000</Price> </Entity> <Entity> <id>101</id> <Specification1>Car model 2</Specification1> <Specification2>Blue</Specification2> <Specification3>Diesel car</Specification3> <Specification4>Ford</Specification4> <Price>5000</Price> </Entity> <Entity> <id>102</id> <Specification1>Car model 3</Specification1> <Specification2>Black</Specification2> <Specification3>SUV</Specification3> <Specification4>Hummer</Specification4> <Price>8000</Price> </Entity> </ProductSETS> </Message> "; $feed = simplexml_load_string($data); $out = ''; foreach ($feed->ProductSETS->Entity as $prod) { $out .= "<div class='product'>\n"; foreach ($prod as $k => $spec) { if ($k != 'id') $out .= "$spec<br>"; } $out .= "</div>\n"; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Example</title> <meta charset='utf-8'> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#find").click( function() { var tid = $("#tid").val() $.get( "", // specify processing file on server (in this case it's same file) {"ajax":"teacher", "tid":tid}, // data to send in request function(resp) { // handle the reponse $.each(resp, function(k,v) { $("#"+k).val(v) }) }, "JSON" // response type ) }) }) </script> <style type='text/css'> body { font-family: calibri, sans-serif; font-size: 12pt; } div.product { margin: 16px; padding: 8px; width: 200px; float: left; } </style> </head> <body> <?= $out ?> </body> </html>
  10. The basics of AJAX are simple. You send a request to be processed on the server and it sends back a response. When responding to an AJAX request, anything output by the server program (stuff that would normally go to the browser screen) is sent back as the response. Here's a simple example (using data from the DB in my tutorial) which accepts a teacher_id, sends it in a request, and recieves back the data for that teacher thne displays it. <?php require 'db_inc.php'; $db = pdoConnect('jointute'); // my cuton connection function - use your connection code //******************** PROCESS AJAX REQUESTS ********************* // // if (isset($_GET['ajax'])) { if ($_GET['ajax']=='teacher') { exit(json_encode(getTeacher($db, $_GET['tid']))); } else { exit('INVALID'); } } // // Functions // function getTeacher($db, $id) { $res = $db->prepare("SELECT t.fname , t.lname , d.deptname as dept FROM teacher t JOIN department d USING (dept_id) WHERE teacherid = ? "); $res->execute([ $_GET['tid'] ]); $row = $res->fetch(); if ($row) { return $row; } else return ['fname'=>'NOT FOUND', 'lname'=>'', 'dept'=>''] ; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Example</title> <meta charset='utf-8'> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#find").click( function() { var tid = $("#tid").val() $.get( "", // specify processing file on server (in this case it's same file) {"ajax":"teacher", "tid":tid}, // data to send in request function(resp) { // handle the response $.each(resp, function(k,v) { $("#"+k).val(v) }) }, "JSON" // response type ) }) }) </script> <style type='text/css'> body { font-family: calibri, sans-serif; font-size: 12pt; } div { margin: 16px; padding: 8px; border: 1px solid gray; } label { display: inline-block; background-color: black; color: white; width: 120px; padding: 8px; margin: 1px 8px;; } </style> </head> <body> <div> <label>Teacher ID (1-20)</label> <input type='number' id='tid' value='0'> <button id='find'>Find</button> </div> <div> <label>First name</label><input type='text' id='fname' value='' readonly><br> <label>Last name</label><input type='text' id='lname' value='' readonly><br> <label>Department</label><input type='text' id='dept' value='' readonly> </div> </body> </html>
  11. Barand

    Join error

    Are you sure you want that LEFT JOIN and not a normal JOIN? There will always be a match with mywines_activity records. LEFT JOINS are slow.
  12. Barand

    Join error

    Well, the error disappeared when I did it that way. You can only do INNER JOINS with the FROM A, B, C method. You have to put the join conditions in the WHERE clause which mixes the table structure with selection criteria In my experience, explicit joins are faster.
  13. Barand

    Join error

    Sorry it's taking a while. I had to create the tables to check the query. If i structure the FROM clause correctly, using explicit JOINS with ON clauses, the error disappears FROM mywines_activity a JOIN mywines_activity_codes d ON a.activity = d.activity_code JOIN mywines w USING (wine_num) LEFT OUTER JOIN (SELECT wine_num, max(date_posted) as sort_date FROM mywines_activity GROUP BY wine_num) s ON s.wine_num = a.wine_num
  14. Barand

    Join error

    You posted in "PHP Coding Help". I moved it to MySQL forum
  15. Barand

    Join error

    What sequence do you want? It usually gives the line number within the query when an SQL error is reported - what is it?
  16. In my experience, between is usually inclusive EG mysql> select id, prod_name -> from products -> where id between 2 and 4; +----+-----------+ | id | prod_name | +----+-----------+ | 2 | Bbb | | 3 | Ccc | | 4 | Ddd | +----+-----------+ and the example given by the OP certainly implies that is the case here too.
  17. Having declared that no sorting is required in any part, your solution depends on the array being sorted. eg echo func([20, 10, 15, 30, 40], 20, 30); // 50 instead of 75
  18. What have you tried so far, and which bit is giving you a problem? You may find useful... array_search()
  19. Now it returns 10 again function ec($n, array $a, array $b) { return $n * $b[1] - $b[0] * $a[0] * $a[1] ; } echo ec( 4, [1,3], [2,4]); // 10 If you post this topic again you will be banned.
  20. You would have to remove "school" from the query. DISTINCT applies to the whole row. What you are doing also has other problems. You could, say, have two different Bill Smith's signed up. One could even have signed up a second time as William Smith.
  21. In the 1980's there was a PC program generation application called "The Last One" which was marketed as "No one will ever need to write a program again". Needless to say, it failed miserably. I get the impression you are trying to create another "Last One". No one will ever need to write another query again. Seriously!?
  22. In my (humble) opinion. I agree wholeheartedly with the above opinions on PDO
  23. Here you are. Now it returns 10 function ec($n, array $a, array $b){ return 10; } We are not going to do your assignment for you.
  24. What substr? How does that image show your current code? I gave it a second try... enough is enough. Good luck.
×
×
  • 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.