Switch query based of databse column value

266
July 26, 2017, at 11:59 PM

I am having trouble switch my SELECT query based on database column value. Here is the issue. I have a link where i get certain values from when user clicks and i use this value to select from a database table based on the value. The issue is that its i not selecting properly. Below are my codes.

$postid = (int) $_GET['post_id'];
$reqid = (int) $_GET['req_id'];
$userpostquery = "SELECT * FROM  users WHERE userid = ?";
$stmt = $db->prepare($userpostquery);
$stmt->bindParam(1, $postid, SQLITE3_INTEGER);
$result = $stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) 
{
    $cname = $row['cname'];
    $profimage = $row['profimages'];
    $caddress = $row['caddress'];
    $briefdes = $row['briefdes'];
    $posttype = $row['posttype'];
    $regas = $row['regas'];
    if ($regas == "Exporter")
    {
        $query = "SELECT * FROM toexapp WHERE req_id = ?";
        $qstmt = $db->prepare($query);
        $qstmt->bindParam(1, $reqid, SQLITE3_INTEGER);
        $qresult = $qstmt->execute();
        while ($qrow = $qresult->fetchArray(SQLITE3_ASSOC))
        {
            $title = $qrow['req_title'];
            $brief = $qrow['req_brief'];
            $image = $qrow['commodityimg'];

            echo '<div class="postviewuserslate">
                <div class="postviewposttitle">'.$title.'</div>
                <div class="postviewimage">
                    <img src="'.$image.'">
                </div>
                <div class="postviewpostdes">'.$brief.'</div>
            </div>';
        }
    }
    if ($regas == "International Buyer")
    {
        $query = "SELECT * FROM toibs WHERE req_id = ?";
        $qstmt = $db->prepare($query);
        $qstmt->bindParam(1, $reqid, SQLITE3_INTEGER);
        $qresult = $qstmt->execute();
        while ($qrow = $qresult->fetchArray(SQLITE3_ASSOC))
        {
            $title = $qrow['req_title'];
            $brief = $qrow['req_brief'];
            $image = $qrow['commodityimg'];
            $image_2 = $qrow['commodityimg_2'];

            echo '<div class="postviewuserslate">
                  <div class="postviewposttitle">'.$title.'</div>
                  <div class="postviewimage">
                      <img src="'.$image.'">
                      <img src="'.$image_2.'">
                  </div>
                  <div class="postviewpostdes">'.$brief.'</div>
              </div>';
        }
    }
}
?>

Please i would like to know how this doesn't work and how to make it work. Thanks.

Rent Charter Buses Company
READ ALSO
Mysql record based on Multiple where clause

Mysql record based on Multiple where clause

I have two tables in that common column is m_id based on that i have to select customer detail with maximum date_time Let's call this table as customer:

280
MySQL indexes not used on LIKE for INT?

MySQL indexes not used on LIKE for INT?

I don't know if this is a bug or a feature, or if I'm doing something wrongI have inherited a MySQL database with a few hundred thousand rows

263
How to use a loop to update multiple comma delimited values into multiple fields

How to use a loop to update multiple comma delimited values into multiple fields

total noob hereI am trying to convert a database I have for administering test

221