Jump to content

Can anyone rewrite this if statement with a mysqli procedural function?


rhs49010

Recommended Posts

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!

 


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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.