Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Evidently not good enough, the correct syntax is $im = imagecreatefromjpeg($file);
  2. Are you sure it really is a jpeg file? You cannot rely on the file extension. Use getimagesize() to check actual type.
  3. Your form markup code and form processing code would be good
  4. Plan D Same PHP code as Plan B but with a variation to the ajax response handling This gives... Code... if (isset($_GET['ajax'])) { $mydata = []; $cols = []; $rows = []; $data = $pdo->query('SELECT user_id as id , firstname , lastname FROM user LIMIT 3 '); $row = $data->fetch(PDO::FETCH_OBJ); $keys = array_keys((array)$row); foreach ($keys as $key) { $cols[] = (object)[ 'name'=>$key, 'title'=>$key ]; } do { $rows[] = $row; } while ($row = $data->fetch(PDO::FETCH_OBJ)); $mydata['columns'] = $cols; $mydata['rows'] = $rows; exit(json_encode($mydata)); } ?> <!DOCTYPE html> <html> <head> <title>Example</title> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <!-- link to jquery functions --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#get-data").click(function() { $.get( "", {"ajax":1}, function(resp) { $("#coldata").html(JSON.stringify(resp.columns)) $("#rowdata").html(JSON.stringify(resp.rows)) $("#crdata").html(JSON.stringify(resp)) }, "JSON" ) }) }) </script> <style type='text/css'> .data { font-family: monospace; } </style> </head> <body> <span id="get-data" class="w3-button w3-blue w3-margin">Get Data</span> <div class="w3-container w3-margin"> <h3>Columns</h3> <div id="coldata" class='data'></div> <h3>Rows</h3> <div id="rowdata" class='data'></div> <h3>All</h3> <div id="crdata" class='data'></div> </div> </body> </html> There should now be something you can use, in whole or in part
  5. You already have a post for this problem. Closing.
  6. Plan C A single script with a single ajax call but the columns and rows are json_encoded separately this time. giving Code... if (isset($_GET['ajax'])) { $mydata = []; $cols = []; $rows = []; $data = $pdo->query('SELECT user_id as id , firstname , lastname FROM user LIMIT 3 '); $row = $data->fetch(PDO::FETCH_OBJ); $keys = array_keys((array)$row); foreach ($keys as $key) { $cols[] = (object)[ 'name'=>$key, 'title'=>$key ]; } do { $rows[] = $row; } while ($row = $data->fetch(PDO::FETCH_OBJ)); $mydata['columns'] = json_encode($cols); $mydata['rows'] = json_encode($rows); exit(json_encode($mydata)); } ?> <!DOCTYPE html> <html> <head> <title>Example</title> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <!-- link to jquery functions --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#get-data").click(function() { $.get( "", {"ajax":1}, function(resp) { $("#coldata").html(resp.columns) $("#rowdata").html(resp.rows) }, "JSON" ) }) }) </script> </head> <body> <span id="get-data" class="w3-button w3-blue w3-margin">Get Data</span> <h3>Columns</h3> <div id="coldata" class='data'></div> <h3>Rows</h3> <div id="rowdata" class='data'></div> </body> </html>
  7. I gave you a single php file which gets both columns and rows. You broke it down into two php files and then ask how to do it with one ??????? Sorry, but you have completely lost me with what you are doing. I give up.
  8. https://www.php.net/manual/en/language.types.string.php
  9. Are you sure you don't want the values for cost and quantity?
  10. Perhaps you could explain how the format my last posted code produced differs from that you have just posted above. (strcmp() tells me they are identical.)
  11. You can't just echo $im to view the image, you need to send a type header then output it with imagejpeg() $im = imagecreatefromjpeg('my_image.jpg'); // output the image header("Content-type: image/jpeg"); imagejpeg($im);
  12. The format I produced was the same as the format in the link you posted, that is $('.table').footable({ "columns": [{"name":"col1", "title": "Col 1"}, {"name":"col2", "title": "Col 2"} ], "rows": [{"col1":"abc", "col2":"def"}, {"col1":"ghi", "col2":"jkl"}, {"col1":"ghi", "col2":"jkl"}, {"col1":"ghi", "col2":"jkl"}, {"col1":"ghi", "col2":"jkl"}] }); If that isn't what you need then you need to tell us what is - no more guessing.
  13. 1 ) the bit before the => is the key, the bit following the => is the value. 2 ) Yes, associative 2b) indexed, or numeric, arrays 2c) But they can be mixed, for example $arr = [ 'This is a key' => 'This is a value', 42 => 'second value', 'Third value' ]; echo $arr['This is a key'] . '<br>'; echo '<pre>', print_r($arr, 1), '</pre>'; which outputs This is a value Array ( [This is a key] => This is a value [42] => second value [43] => Third value ) 3 ) I think the above example answers that.
  14. You're in luck - it didn't time out on me this time <?php $text = file_get_contents('http://86.60.161.24'); echo "<pre>$text</pre>"; ?> Outout analog input 0 is 556 analog input 1 is 465 analog input 2 is 424 analog input 3 is 228 analog input 4 is 364 analog input 5 is 310
  15. I am not psychic. Only you currently know what sequence you want. Only you know which column you would need to sort on to get that desired sequence (and if such a column even exists). Here's a start... SELECT * -- DON'T use *, specify the columns you want. , news.id as nid FROM news LEFT JOIN category ON category.id=news.catid ORDER BY ??????????????????? LIMIT $lim OFFSET $offset;
  16. If I just get the records from my user table they appear in the order they are stored SELECT user_id , firstname , lastname , username , dob FROM user; +---------+-----------+----------+----------+------------+ | user_id | firstname | lastname | username | dob | +---------+-----------+----------+----------+------------+ | 1 | Peter | Dowt | peterd | 2009-12-21 | | 2 | Laura | Norder | lauran | 2010-10-22 | | 3 | Tom | DiCanari | tomd | 2007-10-24 | | 4 | Scott | Chegg | cheggs | 2008-03-08 | | 5 | Polly | Vinyl | pollyv | 2010-12-15 | | 6 | Polly | Styrene | pollys | 2005-08-20 | | 7 | Tom | Catt | tomc | 2011-02-17 | +---------+-----------+----------+----------+------------+ However, I want to list then in order of their dates of birth (dob column) so add an order by clause to the query SELECT user_id , firstname , lastname , username , dob FROM user ORDER BY dob; +---------+-----------+----------+----------+------------+ | user_id | firstname | lastname | username | dob | +---------+-----------+----------+----------+------------+ | 6 | Polly | Styrene | pollys | 2005-08-20 | | 3 | Tom | DiCanari | tomd | 2007-10-24 | | 4 | Scott | Chegg | cheggs | 2008-03-08 | | 1 | Peter | Dowt | peterd | 2009-12-21 | | 2 | Laura | Norder | lauran | 2010-10-22 | | 5 | Polly | Vinyl | pollyv | 2010-12-15 | | 7 | Tom | Catt | tomc | 2011-02-17 | +---------+-----------+----------+----------+------------+
  17. OK, I've done that. What next?
  18. Plan B, giving { "columns":[{"name":"id","title":"id"}, {"name":"firstname","title":"firstname"}, {"name":"lastname","title":"lastname"}], "rows":[{"id":1,"firstname":"Peter","lastname":"Dowt"}, {"id":2,"firstname":"Laura","lastname":"Norder"}, {"id":3,"firstname":"Tom","lastname":"DiCanari"}] } Code $mydata = []; $cols = []; $rows = []; $data = $pdo -> query('SELECT user_id as id , firstname , lastname FROM user LIMIT 3 '); $row = $data->fetch(PDO::FETCH_OBJ); $keys = array_keys((array)$row); foreach ($keys as $key) { $cols[] = (object)[ 'name'=>$key, 'title'=>$key ]; } do { $rows[] = $row; } while ($row = $data->fetch(PDO::FETCH_OBJ)); $mydata['columns'] = $cols; $mydata['rows'] = $rows; echo json_encode($mydata);
  19. I take it that's a "No".
  20. Your link times out when I try to access via my browser.
  21. Is this close to what you want? $mydata = []; $cols = []; $rows = []; $data = $pdo -> query('SELECT user_id as id , firstname , lastname FROM user '); $row = $data->fetch(); $cols = array_keys($row); do { $rows[] = array_values($row); } while ($row = $data->fetch()); $mydata['columns'] = $cols; $mydata['rows'] = $rows; echo json_encode($mydata); givng $mydata = Array ( [columns] => Array ( [0] => id [1] => firstname [2] => lastname ) [rows] => Array ( [0] => Array ( [0] => 1 [1] => Peter [2] => Dowt ) [1] => Array ( [0] => 2 [1] => Laura [2] => Norder ) [2] => Array ( [0] => 3 [1] => Tom [2] => DiCanari ) ) ) JSON... {"columns":["id","firstname","lastname"],"rows":[[1,"Peter","Dowt"],[2,"Laura","Norder"],[3,"Tom","DiCanari"]]}
  22. Have you the correct fopen wrappers enabled? see https://www.php.net/manual/en/function.fopen.php
  23. Or, as the OP is using mysqli print_r($conn->error_list); However a better way is to set mysql error reporting when you make the connection to the server EG mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $conn = mysqli_connect(HOST,USERNAME,PASSWORD,DATABASE); $conn->set_charset('utf8'); If using PDO (recommended) the equivalent is to set the errmode option on connecting $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  24. I can't see a single mention of date_format() in that link. It advocates the use of str_to_date(), which is what my solution used. That still leaves the question of your solution using date_format().
×
×
  • 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.