Jump to content

Recommended Posts

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 by alphasil
Link to comment
https://forums.phpfreaks.com/topic/294058-blank-json-response/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/294058-blank-json-response/#findComment-1503454
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.