Fetching data from database using sqlite in php -


i don't know php.

i trying obtain database using below code, giving, error.

i trying fetch single userid using below code.

can any1 let me know wrong doing??

$query = "select * table userid = '".$obj->{'userid'}."';                  $result = mysql_query($query,$link) or die('errant query:  '.$query);           $posts = array();           if(mysql_num_rows($result))          {                        while($post = mysql_fetch_assoc($result))              {                                    $posts[] = array('posts' =>$post);             }         }          /* output in necessary format */         if($format == 'json')          {             header('content-type: application/json');             echo json_encode(array('posts'=>$posts));         }         else          {             header('content-type: text/xml');             echo '<posts>';             foreach($posts $index => $post)              {                 if(is_array($post))                  {                     foreach($post $key => $value)                      {                         echo '<',$key,'>';                         if(is_array($value))                          {                             foreach($value $tag => $val)                              {                                 echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';                             }                         }                         echo '</',$key,'>';                     }                 }             }             echo '</posts>';         }          /* disconnect db */         @mysql_close($link); 

parse error: syntax error, unexpected ']', expecting t_string or t_variable or t_num_string on line 31.

issue in first line.

change

$query = "select * table userid = '".$obj->{'userid'}."'; 

to

$query = "select * table userid = '".$obj->{'userid'}."'"; 

you not closing double quotes .

update:

to pass headers sent warning message add @ob_start() @ top of page . more info on ob_start() can found here http://php.net/manual/en/function.ob-start.php

so complete thing be

@ob_start(); $query = "select * table userid = '".$obj->{'userid'}."'";  $result = mysql_query($query,$link) or die('errant query:  '.$query);  $posts = array();  if(mysql_num_rows($result))  {                while($post = mysql_fetch_assoc($result))      {                            $posts[] = array('posts' =>$post);     } }  /* output in necessary format */ if($format == 'json')  {     header('content-type: application/json');     echo json_encode(array('posts'=>$posts));     exit(); } else  {    header('content-type: text/xml');    echo '<posts>';    foreach($posts $index => $post)     {       if(is_array($post))        {         foreach($post $key => $value)          {            echo '<',$key,'>';            if(is_array($value))             {               foreach($value $tag => $val)                {                   echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';               }             }             echo '</',$key,'>';            }         }     }     echo '</posts>'; } /* disconnect db */ @mysql_close($link); 

hope helps :)


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -