两个mysql查询在同一页面上搜索?

时间:2017-01-24 21:42:37

标签: php jquery mysql

所以我在jQuery移动页面上有两个MySql搜索,但它们不能一起工作。

以下是代码:

我的index.php代码:

<?php
    require "functions.php";

    $posts = getAllPosts();
    $posts = getSearchPosts();
?>

<?php 
    for( $p = 0; $p < count( $posts ); $p++ )
    {
?>

<div class="ui-corner-all custom-corners">
  <div id="searchpost">
    <?php echo $posts[$p]["search_role"];?>   <!-- using getSearchPosts -->
    <?php echo $posts[$p]["search_genre"];?>

    <?php echo $posts[$p]["user_first_name"];?> <!-- using getAllPosts -->
    <?php echo $posts[$p]["user_last_name"];}?>
  </div>
</div>

的functions.php:

function getSearchPosts()
{
    require "config.php";
    $posts = $c->query ( "SELECT * FROM posts" );

    if ( $posts->num_rows > 0 ) 
    {
        while( $row = $posts2->fetch_assoc() ) 
        {
            $postData[] = array( "user_id" => $row[ "user_id" ], "search_role" => $row[ "search_role" ], "search_genre" => $row[ "search_genre" ] );
        }
    } else {
        return "No Data";
    }
    return $postData;
}

function getAllPosts()
{   
    require "config.php";

    $posts = $c->query ( "SELECT * FROM users" );
    if ( $posts->num_rows > 0 ) 
    {
        while( $row = $posts->fetch_assoc() ) 
        {
            $postData[] = array( "user_id" => $row[ "user_id" ], "user_first_name" => $row[ "user_first_name" ], "user_last_name" => $row[ "user_last_name" ] );
        }
    } else {
        return "No Data";
    }
    return $postData;
}

我假设我要将一个函数的$posts更改为其他内容,例如$posts -> $search或其他内容,但更改后不会回显任何内容。我可以做些什么来同时完成两个搜索?

1 个答案:

答案 0 :(得分:0)

将它们作为两个独立的循环。在同一个DIV中显示它们是没有意义的,因为两个查询的结果之间没有对应关系。

var time = Date()

func shoot(after timeInterval: Double) {
    guard Date() - timeInterval > time else {
        print("WAIT")
        return
    }
    print("SHOOT")
    time = Date() // reset the timer
}

// CALL THIS INSIDE touchesEnded
shoot(after: 1)