alphasil Posted January 19, 2015 Share Posted January 19, 2015 (edited) Hi I'm having this issue, when i put an url who must show me records i have blank html page <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); require_once 'database_connection.php'; $post=array( 'limit'=>(isset($_REQUEST['rows']))?$_REQUEST['rows']:'', 'page'=>(isset($_REQUEST['page']))?$_REQUEST['page']:'', 'orderby'=>(isset($_REQUEST['sidx']))?$_REQUEST['sidx']:'', 'orden'=>(isset($_REQUEST['sord']))?$_REQUEST['sord']:'', 'search'=>(isset($_REQUEST['_search']))?$_REQUEST['_search']:'', ); $se =""; if($post['search'] == 'true'){ $b = array(); $search['like']=elements(array('utilizador','email'),$_REQUEST); foreach($search['like'] as $key => $value){ if($value != false) $b[]="$key like '%$value%'"; } $search['where']=elements(array('nome','utilizador','email'),$_REQUEST); foreach($search['where'] as $key => $value){ if($value != false) $b[]="$key = '$value'"; } $se=" where ".implode(' and ',$b ); } $query = mysql_query("select count(*) as t from utilizador".$se); if(!$query) echo mysql_error(); $count = mysql_result($query,0); if( $count > 0 && $post['limit'] > 0) { $total_pages = ceil($count/$post['limit']); if ($post['page'] > $total_pages) $post['page']=$total_pages; $post['offset']=$post['limit']*$post['page'] - $post['limit']; } else { $total_pages = 0; $post['page']=0; $post['offset']=0; } $sql = "SELECT idutilizador, nome, utilizador, telefone, email, password FROM utilizador ".$se; if( !empty($post['orden']) && !empty($post['orderby'])) $sql .= " ORDER BY $post[orderby] $post[orden] "; if($post['limit'] && $post['offset']) $sql.=" limit $post[offset], $post[limit]"; elseif($post['limit']) $sql .=" limit 0,$post[limit]"; $query = mysql_query($sql); if(!$query) echo mysql_error(); $result = array(); $i = 0; while($row = mysql_fetch_object($query)){ $result[$i]['id']=$row->idutilizador; $result[$i]['cell']=array($row->idutilizador,$row->nome,$row->utilizador,$row->telefone,$row->email,$row->password); $i++; } $json = new stdClass(); $json->rows=$result; $json->total=$total_pages; $json->page=$post['page']; $json->records=$count; echo json_encode($json); function elements($items, $array, $default = FALSE) { $return = array(); if ( ! is_array($items)){ $items = array($items); } foreach ($items as $item){ if (isset($array[$item])){ $return[$item] = $array[$item]; }else{ $return[$item] = $default; } } return $return; } ?> *Update It works if i put $result[$i]['cell']=array($row->idutilizador,$row->telefone,$row->email,$row->password); So i'm think it's because in $nome(ex: Luis Miguel) and $utlizador(ex Susana Maria) don't accept this (space between words) it is correct? Edited January 19, 2015 by alphasil Quote Link to comment Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 Check the query that is actually submitted by echoing the final SQL string that is executed echo "select count(*) as t from utilizador".$se; It helps debugging if you always build the sql as a string variable first then execute that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.