Jump to content

mahenda

Members
  • Posts

    146
  • Joined

  • Last visited

Everything posted by mahenda

  1. //look my code CREATE TABLE IF NOT EXISTS first ( fid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, p_name varchar(60) NOT NULL ); CREATE TABLE IF NOT EXISTS second ( sed int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, firstname varchar(20) NOT NULL, fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS third ( thid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS fourth ( fid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS fifth ( fiid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); CREATE TABLE IF NOT EXISTS sixth ( sid int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, start_date date NOT NULL, end_date date NOT NULL, sed int(11) NOT NULL, FOREIGN KEY (sed) REFERENCES second(sed), fid int(11) NOT NULL, FOREIGN KEY (fid) REFERENCES first(fid) ); //As you can see above, I want to create a single query to query all data at the samee time i.e //All table from third table depend on first and second table, but the second table have column firstname and the first table has the p_name column //I want SELECT second.*, third.* FROM second INNER JOIN third ON third.sed = second.sed SELECT second.*, fourth.* FROM second INNER JOIN fourth ON fourth.sed = second.sed SELECT second.*, fifth.* FROM second INNER JOIN fifth ON fifth.sed = second.sed SELECT second.*, sixth.* FROM second INNER JOIN sixth ON sixth.sed = second.sed ....WHERE fid = 1; //I want to combine these queries into single query ie, $newqueries = '.....';
  2. It give an the link like http://localhost/aps/undefined Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11 //The php code to fetch data //The php code to fetch data <?php include('db.php'); $query = ''; $output = array(); $query .= "SELECT * FROM users "; if(isset($_POST["search"]["value"])) { $query .= 'WHERE first_name LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR last_name LIKE "%'.$_POST["search"]["value"].'%" '; } if(isset($_POST["order"])) { $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' '; } else { $query .= 'ORDER BY id DESC '; } if($_POST["length"] != -1) { $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $statement = $connection->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $data = array(); $filtered_rows = $statement->rowCount(); foreach($result as $row) { $sub_array = array(); $sub_array[] = $row["first_name"]; $sub_array[] = $row["last_name"]; $sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>'; $sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>'; $data[] = $sub_array; } $output = array( "draw" => intval($_POST["draw"]), "recordsTotal" => $filtered_rows, "recordsFiltered" => get_total_all_records(), "data" => $data ); echo json_encode($output); ?> //javasrcipt jquery var dataTable = $('#user_data').DataTable({ "processing":true, "serverSide":true, "order":[], "ajax":{ url:"fetch.php", type:"POST" }, "columnDefs":[ { "targets":[0, 3, 4], "orderable":false, }, ] });
  3. //The php code to fetch data <?php include('db.php'); $query = ''; $output = array(); $query .= "SELECT * FROM users "; if(isset($_POST["search"]["value"])) { $query .= 'WHERE first_name LIKE "%'.$_POST["search"]["value"].'%" '; $query .= 'OR last_name LIKE "%'.$_POST["search"]["value"].'%" '; } if(isset($_POST["order"])) { $query .= 'ORDER BY '.$_POST['order']['0']['column'].' '.$_POST['order']['0']['dir'].' '; } else { $query .= 'ORDER BY id DESC '; } if($_POST["length"] != -1) { $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; } $statement = $connection->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $data = array(); $filtered_rows = $statement->rowCount(); foreach($result as $row) { $sub_array = array(); $sub_array[] = $row["first_name"]; $sub_array[] = $row["last_name"]; $sub_array[] = '<button type="button" name="update" id="'.$row["id"].'" class="btn btn-warning btn-xs update">Update</button>'; $sub_array[] = '<button type="button" name="delete" id="'.$row["id"].'" class="btn btn-danger btn-xs delete">Delete</button>'; $data[] = $sub_array; } $output = array( "draw" => intval($_POST["draw"]), "recordsTotal" => $filtered_rows, "recordsFiltered" => get_total_all_records(), "data" => $data ); echo json_encode($output); ?> //javasrcipt jquery var dataTable = $('#user_data').DataTable({ "processing":true, "serverSide":true, "order":[], "ajax":{ url:"fetch.php", type:"POST" }, "columnDefs":[ { "targets":[0, 3, 4], "orderable":false, }, ] }); Look the code
  4. Don't give up buddy, I know you used a single file but remember the footable plugin requires two files, one which provide columns and another which provides rows, so the single one refused to display the data to the view until I broke that to two PHP files the one with rows and another with columns, it worked but the one issue here is how to add links on each rows on the table? have you tested it practically with footable not only php script?
  5. Thank you for your help, the code you provide me it work and display data in server side on console but it was never working in the view table, but for now I modified the code to give out something like //first columns php [{"name":"id","title":"id"}, {"name":"firstname","title":"firstname"}, {"name":"lastname","title":"lastname"}], //first rows php [{"id":1,"firstname":"Peter","lastname":"Dowt"}, {"id":2,"firstname":"Laura","lastname":"Norder"}, {"id":3,"firstname":"Tom","lastname":"DiCanari"}] then it worked but i have to ask you last questions how can i use the same php file for both columns and rows, Also how to add custom link in footable, just when one click it will open other page and there i will do something look on how i modified the your code REMEMBER: You gave out single php file butt i broke it like; //you provided $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); //First thing I did //I created php file for fetching a columns only $mydata = []; $cols = []; $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[] = [ 'name'=>$key, 'title'=>$key ]; } $mydata = $cols; echo json_encode($mydata); //do not forget header('Content-Type: application/json'); //second thing I did //I created php file for fetching a columns only //you provided $mydata = array(); $data = $pdo -> prepare('SELECT user_id as id , firstname , lastname FROM user LIMIT 3 '); $data -> execute(); while($result = $data->fetch()) { $mydata[] = array( 'id' => $result['id'], 'firstname' => $result['firstname'], 'lastname' => $result['lastname'] //but how to add some button here since the columns are coming directry from database 'view' => '<button type="button" name="view" id="'.$result["id"].'" class="btn btn-secondary btn-xs rounded-circle delete" data-toggle="tooltip" data-placement="top" title="view"><i class="zmdi zmdi-more"></i></button>'; ); } echo json_encode($mydata);
  6. I want get the data in this format please //first columns php [{"name":"id","title":"id"}, {"name":"firstname","title":"firstname"}, {"name":"lastname","title":"lastname"}], //first rows php [{"id":1,"firstname":"Peter","lastname":"Dowt"}, {"id":2,"firstname":"Laura","lastname":"Norder"}, {"id":3,"firstname":"Tom","lastname":"DiCanari"}] but when I'm using my first code i get //first rows php [1,"Peter","Dowt", 2,"Laura","Norder", 3,"Tom","DiCanari"]
  7. Of course this is a footable format, but keep in mind that the JavaScript side requires both rows and columns that have already been defined as a property in the plugin, now the problem is how to integrate a PHP file with the JSON data to replace those columns.json and row.json file, look here jQuery(function($){ $('.table').footable({ "columns": $.get('columns.json'), "rows": $.get('rows.json') }); }); I want jQuery(function($){ $('.table').footable({ "columns": $.get('columns.php'), "rows": $.get('rows.php') }); }); But we remember our php file produce both rows and columns at the same time i.e { "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"}] } The data above came with keyword columns and rows, I think this is a problem because there is no data are displayed, I think they were supposed to come as //first columns php [{"name":"id","title":"id"}, {"name":"firstname","title":"firstname"}, {"name":"lastname","title":"lastname"}], ////first rows php [{"id":1,"firstname":"Peter","lastname":"Dowt"}, {"id":2,"firstname":"Laura","lastname":"Norder"}, {"id":3,"firstname":"Tom","lastname":"DiCanari"}] and then we replace the above file on jQuery(function($){ $('.table').footable({ "columns": $.get('columns.php'), "rows": $.get('rows.php') }); }); May be there is another way, but my altenative was a datatable which found at datatable.net, but when i use ajax the pagination link not working look at this thread
  8. Ifollowed this example at webdamn but it seem that there is a problem when clicking previous, next and other links like 1,2... on pagination no any modified code datatable plugin it give out, http://localhost/aps/undefined Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.35 (Win32) OpenSSL/1.1.0i PHP/7.2.11
  9. How to remove these keyword columns and rows in php i.e Code [{"name":"id","title":"id"}, {"name":"firstname","title":"firstname"}, {"name":"lastname","title":"lastname"}], [{"id":1,"firstname":"Peter","lastname":"Dowt"}, {"id":2,"firstname":"Laura","lastname":"Norder"}, {"id":3,"firstname":"Tom","lastname":"DiCanari"}]
  10. I saw this statement The problem was that, when reading a file, the promise passed to Footable resolves as a string array instead of an array of JavaScript objects containing row data. here https://stackoverflow.com/questions/32960406/footable-v3-ajax-data-loading-error-no-columns-supplied what does this mean
  11. It was my fault, i troubleshooted it but the problem is FooTable: unhandled error thrown during initialization. Error: No columns supplied. at c.parseFinalize (footable.min.js:8) at Object.<anonymous> (footable.min.js:8) at mightThrow (jquery-3.3.1.min.js:3534) at process (jquery-3.3.1.min.js:3602) what does it mean, please refer on the previous jquery
  12. jquery-3.3.1.min.js:3818 jQuery.Deferred exception: Cannot use 'in' operator to search for 'length' in {"columns":["id","first_name","last_name"],"rows":[[1,"Bob","Johnson"],[2,"Paul","Prince"],[3,"Jimmy","Jackson"]]} at isArrayLike (http://localhost/aps/assets/vendor/jquery-3.3.1.min.js:489:33) at Function.map (http://localhost/aps/assets/vendor/jquery-3.3.1.min.js:440:8) at c.parseFinalize (http://localhost/aps/assets/vendor/footable/js/footable.min.js:9:2668) at Object.<anonymous> (http://localhost/aps/assets/vendor/footable/js/footable.min.js:9:2445) at mightThrow (http://localhost/aps/assets/vendor/jquery-3.3.1.min.js:3534:29) at process (http://localhost/aps/assets/vendor/jquery-3.3.1.min.js:3602:12) undefined jQuery.Deferred.exceptionHook @ jquery-3.3.1.min.js:3818
  13. I have php file which return data in json format <?php include_once('con.php'); $mydata = array(); $data = $con -> prepare('SELECT * FROM user'); $data -> execute(); while($result = $data->fetch()) { $mydata[] = $result['id']; $mydata[] = $result['first_name']; $mydata[] = $result['last_name']; } echo json_encode($mydata); ?> the problem is the footable require both columns and rows how to get colums? $(document).ready( function() { var ft = FooTable.init('#user', { columns: $.get("how to get the table column"), rows: $.get("row.php") }); }); There is no documentation about how to do that with php look here https://fooplugins.github.io/FooTable/docs/examples/advanced/ajax.html
  14. the second database found on the cloud i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders); i get {"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}}
  15. When am doing this; $(".employee #name").html(data.employee.name); $(".employee #intro").html(data.employee.intro); $(".department #name").html(data.department.name); $(".department #desc").html(data.department.desc); Nothing work can you help me here, I don't want to change the field names
  16. The above php return the correct JSON DATA, the issue here is how to pass them to the welcome.blade.php , i know this in the normal php and I was supposed to do the following //the ajax in normal php $.ajax({ type: "GET", url: "/homeController.php", success: function (data) { $(".employee #name").html(data.name); $(".employee #intro").html(data.intro); $(".department #name").html(data.name); $(".department #desc").html(data.desc); } }); Help me i cant figure it in laravel
  17. //my controller <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class homeController extends Controller { public function index() { $employee = DB::table('employee')->orderBy('id','desc')->get(); $department = DB::table('department')->orderBy('id','desc')->get(); //I added this line but the data came in the json format so how to pass it to the view with ajax but remember they are comming from different tables return response()->json(array('employee' => $employee , 'department' => $department)); } } -
  18. //my controller <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class homeController extends Controller { public function index() { $employee = DB::table('employee')->orderBy('id','desc')->get(); $department = DB::table('department')->orderBy('id','desc')->get(); return view('index', ['employee' => $employee , 'department' => $department]); } } //my routes Route::get('index','homeController@index'); //my view using blade temmplating engine @foreach($employee as $emp) <div class="employee"> <b>{{ $emp->name }} </b> <a href="employee/{{ $emp->id }}"> <p class="intro">{{ substr($emp->intro ,0, 50) }}...</p> </a> </div> @endforeach @foreach($department as $dep) <div class="department"> <b>{{ $dep->name }} </b> <a href="department/{{ $dep->id }}"> <p class="desc">{{ substr($dep->description ,0, 100) }}...</p> </a> </div> @endforeach I want to fetch using ajax, how can i do it, teach/help me
  19. //my php code sample <?php include_once('con.php'); if(isset($_POST['username'])){ $message = []; if(empty($_POST['username'])){ $message['username'] = 'username required'; } #some validation continue... $data = $_POST['username']; if (count($errors) === 0){ #ccode... $message['username'] = 'success your name saved'; } } ?> //my jquery ajax $('.username').click(function() { $.ajax({ url: 'user.php', method: 'POST', data: $('.user').serialize(), success: function(data) { swal('Wow!','success message from php','success'); }, error: function(data) { swal('Oops!','error message from php','error'); } }); return false; });
×
×
  • 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.