简体   繁体   中英

Having trouble accessing all data from mysql tables

Im trying to run a query that will echo the rowcount from the databse. at the moment it only shows the last one not all of them. Can someone please help me on how to show all the rows instead of just one.

    $search = $_GET['pc'];
$approved = 'Approved';
$live = 'Live';
$q = $handler->prepare("SELECT * FROM store WHERE pc = ? OR plus_1 = ? OR plus_2 = ? OR plus_3 = ? OR plus_4 = ?");
$q->bindParam(1, $search);
$q->bindParam(2, $search);
$q->bindParam(3, $search);
$q->bindParam(4, $search);
$q->bindParam(5, $search);
$q->execute();
if($q->rowCount() > 0){
    while($r = $q->fetch()){
        $local_id = $r['user_id'].;
    }

    $q = $handler->prepare("SELECT * FROM users WHERE id = ? AND status = ?");
    $q->bindParam(1, $local_id);
    $q->bindParam(2, $approved);
    $q->execute();
    if($q->rowCount() > 0){
    while($r = $q->fetch()){
        $local_id_2 = $r['id'].;
    }

        $q = $handler->prepare("SELECT * FROM offers WHERE user_id = ? AND status = ? AND approved = ?");
        $q->bindParam(1, $local_id_2);
        $q->bindParam(2, $live);
        $q->bindParam(3, $approved);
        $q->execute();



echo        $viewAll = $q->rowCount();

    }
}

if tried echoing all the $local_id and local_id2 but only the first one ($local_id) echos all of the data the rest just echos the last $lcoal_id from the first one.. Thanks in advance.

将使用临时修复程序来创建另一个包含我需要的所有数据的表。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM