SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2014
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with convert mysqli to prepared statement pagination

    My code is with mysqli_* and I want to make it with prepared statements. I've read some tutorials but is a little bit hard for newbie to understant what and how. So I started and this is so far what I have... just the beginning. So from here to down can someone help me?
    PHP Code:
    if(isset($_GET['oke_id'])){
                
    $joke_id $_GET['oke_id'];

                
    $qry $con->prepare("SELECT * FROM oke WHERE oke_cat = ?");
                
    $qry->bind_param('i'$oke_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($resultMYSQL_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($resultMYSQL_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/>'
    I have trouble from $result->fetch_array(); to down. Now they are mixed and don't realy know what to do?

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing I notice is $oke_id is not defined. I am thinking you meant for that to be $joke_id.
    Ben

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2014
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by phpMyDirectory View Post
    One thing I notice is $oke_id is not defined. I am thinking you meant for that to be $joke_id.
    Yes, i copy/paste and forget to edit this. Also I can't edit my post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •