Goro
Goro

Reputation: 499

Prepared statements doesn't return results

I trying to do all my querys with prepared statements but is new for me and I have some troubles. This is first query and doesn't echo result from table. This is what I've done so far. May be is realy newbie question but is something completely new for me.

if(isset($_GET['joke_id'])){
            $joke_id = $_GET['joke_id'];

            $qry = $con->prepare("SELECT * FROM joke WHERE joke_cat = ?");
            $qry->bind_param('i', $joke_id);
            $qry->execute();
            $result = $qry->get_result();
            $result->fetch_array();

    $result = mysqli_query($con, $qry) or die("Query failed: " . mysqli_errno($con));*/
            $line = mysqli_fetch_array($result, MYSQL_BOTH);

            if (!$line) echo '';
            $previd = -1;
            $currid = $line[0];
            if (isset($_GET['id'])) {
                $previous_ids = array();
                do {
                    $previous_ids[] = $line[0];
                    $currid = $line[0];
                    if ($currid == $_GET['id']) break;
                    $previd = end($previous_ids);
                    $line = mysqli_fetch_array($result, MYSQL_BOTH);
                } while ($line);
            }
   if ($line) {
                echo "<div id=\"box\">";
                echo nl2br($line['text']) . "<br /><br />";
                echo "<div id=\"share\"><span class='st_facebook' displayText='Facebook'></span>
                <span class='st_twitter' displayText='Tweet'></span>
                <span class='st_googleplus' displayText='Google +'></span></div>";
                echo '<br /><br /><br />';
                echo "</div>";

            }
            else echo '<p>Empty category</p><br/>';

This is what I use right now before to try PDO and it's work with no problems.

qry = "SELECT * FROM joke WHERE joke_cat = '$joke_id'";
            $result = mysqli_query($con, $qry) or die("Query failed: " . mysqli_errno($con));

Upvotes: 0

Views: 77

Answers (1)

rscata
rscata

Reputation: 521

$_GET['joke_id'] and $_GET['joke_cat'] is set ?

or try

$qry = $con->prepare("SELECT * FROM joke WHERE joke_cat =:joke_cat");
$qry->bindParam(':joke_cat', $_GET['joke_cat'], PDO::PARAM_STR);
$qry->execute();
$result = $qry->fetchAll();

Upvotes: 1

Related Questions