Jump to content

Problem moving to mysqli


Recommended Posts

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`

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 by SF23103
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.