SF23103 Posted December 12, 2013 Share Posted December 12, 2013 (edited) I am trying to be good and re-write all of my scripts to use mysqli instead of mysql_query & mysql_result etc. I have written the code below, but I am stuck. Here's an explanation: while($row = $result->fetch_assoc()){ echo $row['col_1'] ; } results echo's "ON" or "OFF" based on the settings of another app. I want to assign that result (ON or OFF) to a variable $status. I will then use that to do something else: if ($status == 'OFF' ) $display_this = 'on.gif' ; if ($status == 'ON' ) $display_this = 'off.gif'; Here is the code I have written so far: <?php include "database_login.php"; $db = new mysqli('localhost', $username, $password, $database); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } $sql = <<<SQL SELECT * FROM `ft_data_18` SQL; if(!$result = $db->query($sql)){ die('There was an error running the query [' . $db->error . ']'); } while($row = $result->fetch_assoc()){ echo $row['col_1'] ; } $db->close(); ?> Edited December 12, 2013 by SF23103 Quote Link to comment https://forums.phpfreaks.com/topic/284728-problem-moving-to-mysqli/ Share on other sites More sharing options...
Barand Posted December 12, 2013 Share Posted December 12, 2013 Once you have the value of $row['col_1'] the processing of the status gif is exactly the same whether you use mysql or mysqli. Quote Link to comment https://forums.phpfreaks.com/topic/284728-problem-moving-to-mysqli/#findComment-1462175 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.