Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( isset( $_GET['q'] ) ){
- # change this to suit - add your db connection
- # and remove these lines
- chdir('../../');
- set_include_path( sprintf('%s/dbo', getcwd() ) );
- require 'db-conn-details.php';
- require 'mysqli-conn.php';
- # change this to suit
- $sql='select * from `country` where `name` like ? order by `name`';
- #do NOT change below
- $name='%' . $_GET['q'] . '%';
- $stmt=$db->prepare( $sql );
- $stmt->bind_param('s',$name);
- $stmt->execute();
- $res=$stmt->get_result();
- $fields=array_column( $res->fetch_fields(), 'name' );
- $html='<table>';
- $html.='<tr>';
- foreach( $fields as $field ){
- $html.=sprintf('<th>%s</th>',ucwords($field));
- }
- $html.='</tr>';
- while( $rs=$res->fetch_object() ){
- $html.='<tr>';
- foreach( $fields as $field ){
- $html.=sprintf('<td>%s</td>',$rs->{$field});
- }
- $html.='</tr>';
- }
- $html.='</table>';
- $stmt->free_result();
- $stmt->close();
- exit( $html );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement