2015-02-11 52 views
-1

嗨,在下面它返回成功的消息,但我没有得到id,groupnames。 如何在下面的代码中执行select查询。我将记录id和groupname的详细信息。如何在php中显示查询记录

任何一个可以帮助我

PHP

case "DispalyGroupDetails": 
     $userId = authenticateUser($db, $username, $password); 

     if ($userId != NULL) 

     { 

      if (isset($_REQUEST['username']))   
      {    
       $username = $_REQUEST['username']; 



       $sql = "select Id from users where username='$username' limit 1"; 

       if ($result = $db->query($sql)) 

       { 
         if ($row = $db->fetchObject($result)) 

         {  

            $sql = "select g.id,g.groupname from `users` u, `friends` f,`group` g 
            where u.Id=f.providerId and f.providerId=g.providerId"; 
            echo $sql; 


            if ($db->query($sql)) 
            { 
             $out = SUCCESSFUL; 
            } 
            else 
            { 
              $out = FAILED; 
            } 

         } 
         else 
         { 
          $out = FAILED;      
         } 
       } 

       else 
       { 
         $out = FAILED; 
       }    
      } 

      else 
      { 
        $out = FAILED; 
      }   
     } 
     else 
     { 
      $out = FAILED; 
     } 
    break; 
+0

没有必要那么多,如果条件的,可以单用,如果检查多个条件'&&'或''||等 – 2015-02-11 10:34:02

+0

$ SQL =“从选择g.id,g.groupname' users' U,'friends'楼'group'克 \t \t \t \t \t \t \t \t \t其中u.Id = f.providerId和f.providerId = g.providerId“; json格式如何执行查询 – user1 2015-02-11 10:36:23

回答

1

尝试这样的事情。您需要获取查询的内容,而不是仅仅查看查询是否成功。

$sql = "select g.id,g.groupname from `users` u, `friends` f,`group` g 
           where u.Id=f.providerId and f.providerId=g.providerId"; 

echo $sql; 

$theResult = $db->query($sql); 

if ($theResult) { 
    $theRow = $db->fetchObject($theResult); 
    echo $theRow->id; 
    echo $theRow->groupname; 
    //Etc 
    $out = SUCCESSFUL; 
} else { 
    $out = FAILED; 
} 
+0

如何获取id和groupnames的数组如何写一个 – user1 2015-02-11 10:58:41

+1

while($ theRow = $ db-> fetchObject($ theResult)){ echo $ theRow-> id; echo $ theRow-> groupname; } – Oliverb 2015-02-11 12:19:52

相关问题