2010-02-25 2 views
2

아래 코드는 제가 사용하고있는 코드입니다. 별도로 그들은 둘 다 그들이해야 할 일을하지만 두 번째의 첫 번째 문장에서 결과를 사용하려고하면 아무 것도 반환하지 않습니다. 나는 첫 번째 문장은 항상 올바른 데이터를 반환합니다. 누군가 내가 잘못하고 있다고 말할 수 있습니까? 추가 검사시 감사Mysqli select 문이 다른 Mysqli select 문에서 결과와 잘 맞지 않습니다.

$connection = mysqli_connect($hostname, $username, $password, $dbname); 

$sql = "SELECT banner".$number_id."_id FROM newcms_projectbanners WHERE region_id = ?"; 

$stmt = mysqli_prepare($connection, $sql); 

    mysqli_stmt_bind_param($stmt, "s", $region_id); 
    mysqli_stmt_execute($stmt); 
    mysqli_stmt_bind_result($stmt, $banner_id); 

    // display the results 
    mysqli_stmt_fetch($stmt); 

$sql1 = "SELECT `title`, `active`, `linkto` FROM newcms_banners WHERE id = ?"; 

$stmt1 = mysqli_prepare($connection, $sql1); 

    mysqli_stmt_bind_param($stmt1, "s", $banner_id); 
    mysqli_stmt_execute($stmt1); 
    mysqli_stmt_bind_result($stmt1, $title, $active, $linkto); 

    // display the results 
    mysqli_stmt_fetch($stmt1); 

편집

는, 내가 이런 식으로 두 개의 문을 실행할 수 없습니다 것 같다. 그것을하는 올바른 방법은 무엇입니까? 감사합니다

답변

1

아래 코드는 트릭을 수행합니다.

$post_stmt = $db_connection->prepare("SELECT banner".$number_id."_id FROM newcms_projectbanners WHERE region_id = ?"); 
$comment_stmt = $db_connection->prepare("SELECT title, active, linkto FROM newcms_banners WHERE id = ?"); 

$post_stmt->bind_param('i', $region_id); 
if ($post_stmt->execute()) 
{ 
    $post_stmt->store_result(); 
    $post_stmt->bind_result($banner_id); 

    if ($post_stmt->fetch()) 
    { 
     $comments = array(); 

     $comment_stmt->bind_param('i', $banner_id); 
     if ($comment_stmt->execute()) 
     { 
     $comment_stmt->bind_result($title, $active, $linkto); 
     while ($comment_stmt->fetch()) 
     { 
      $html = "<fieldset title='$label'>" . PHP_EOL; 
      $html .= "<form action='$action' id='$id' method='post' class='$class'>" . PHP_EOL; 
      $html .= "<label for'title'>Title</label>" . PHP_EOL; 
      $html .= "<input type='text' name='title' value='$title' /><br />" . PHP_EOL; 
      $html .= "<label for'active'>Active</label>" . PHP_EOL; 
      $html .= "<input type='checkbox' name='active' checked /><br />" . PHP_EOL; 
      $html .= "<label for'linkto'>Link to</label>" . PHP_EOL; 
      $html .= "<input type='text' name='linkto' value='$linkto' /><br />" . PHP_EOL; 
      $html .= "<input type='hidden' name='hidden' value='$banner_id'>" . PHP_EOL; 
      $html .= "<input type='submit' value'Done'>" . PHP_EOL; 
      $html .= "</form>" . PHP_EOL; 
      $html .= "</fieldset>" . PHP_EOL; 

     } 
     } 
     else 
     { 
     printf("Comment statement error: %s\n", $comment_stmt->error); 
     } 
    } 

    $post_stmt->free_result(); 
} 
else 
{ 
printf("Post statement error: %s\n", $post_stmt->error); 
} 

$post_stmt->close(); 
$comment_stmt->close(); 

$db_connection->close();