-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
-
Are you sure it really is a jpeg file? You cannot rely on the file extension. Use getimagesize() to check actual type.
-
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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 -
You already have a post for this problem. Closing.
-
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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> -
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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. -
all differences with using single quotes and double quotes
Barand replied to ajetrumpet's topic in PHP Coding Help
https://www.php.net/manual/en/language.types.string.php -
Can't get a real value with: document.getElementById(keyword1).value;
Barand replied to JoshEir's topic in Javascript Help
Are you sure you don't want the values for cost and quantity? -
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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.) -
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);
-
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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. -
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.
-
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
-
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;
-
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 | +---------+-----------+----------+----------+------------+
-
OK, I've done that. What next?
-
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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); -
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
I take it that's a "No". -
Your link times out when I try to access via my browser.
-
I'm trying to work with footable bootstrap plugin
Barand replied to mahenda's topic in PHP Coding Help
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"]]} -
Have you the correct fopen wrappers enabled? see https://www.php.net/manual/en/function.fopen.php
-
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);
-
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().