rhs49010 Posted September 29, 2013 Share Posted September 29, 2013 The following is a simple ad rotation script it works fine until it gets to the 'if' statement. I need to check if the 'shown column data is set to 0. obviously I can find an answer anywhere on the web. <?php include 'test_db_conn.php'; $ads = mysqli_query($conn,"SELECT `advert_id`,`images` FROM `adverts` WHERE `shown` = 0 ORDER BY `advert_id` ASC LIMIT 1")or die("SQL Error line ".__LINE__ . mysqli_errno()); while ($row = mysqli_fetch_assoc($ads)) { $advert_id = $row ['advert_id']; $images = $row ['images']; echo '<a href="go.php?advert_id=' .$advert_id. '"target="_blank"><img src="'.$images.'" /></a>'; $result = mysqli_query ($conn,"UPDATE `adverts` SET `shown`=1, `impressions`=`impressions` +1 WHERE `advert_id`= $advert_id"); $shown = mysqli_query($conn,"SELECT COUNT(`advert_id`) FROM `adverts` WHERE 'shown' =0"); // This was originally written with a mysql_result function How can I get the same functionality the a mysqli procedural function. if (mysqli_? ($shown,0) == 0) { mysqli_query($conn,"UPDATE `adverts` SET `shown`=0"); } } ?> Thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/282542-can-anyone-rewrite-this-if-statement-with-a-mysqli-procedural-function/ Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 You'd use mysqli_stmt_fetch() mysqli doesn't have mysqli_result. Quote Link to comment https://forums.phpfreaks.com/topic/282542-can-anyone-rewrite-this-if-statement-with-a-mysqli-procedural-function/#findComment-1451775 Share on other sites More sharing options...
RobertP Posted September 30, 2013 Share Posted September 30, 2013 BAM!! If your going to spend your time learning a new db interface.. do it right with pdo Quote Link to comment https://forums.phpfreaks.com/topic/282542-can-anyone-rewrite-this-if-statement-with-a-mysqli-procedural-function/#findComment-1451790 Share on other sites More sharing options...
vinny42 Posted September 30, 2013 Share Posted September 30, 2013 You'd use mysqli_stmt_fetch() If you are using prepared statements, yes. But he's not, so no. :-) mysqli doesn't have mysqli_result. http://www.php.net/manual/en/class.mysqli-result.php If your going to spend your time learning a new db interface.. do it right with pdo PDO pretends that all databases have the same API. They don't, which means that PDO's behaviour is still different from database to database, which is worse than having separate API's. The API for PostgreSQL simply doesn't have lastinsertid() so you cannot mistakenly use it and get false results, like you can with PDO. You are much better off understanding how the actual API works than to rely on how the creator of the PDO stuff thinks he should translate the actual API to PDO's API. Quote Link to comment https://forums.phpfreaks.com/topic/282542-can-anyone-rewrite-this-if-statement-with-a-mysqli-procedural-function/#findComment-1451825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.