Solved

Resolve a "Warning: mysqli_fetch_array()...

Posted on 2014-09-15
3
140 Views
Last Modified: 2014-09-26
Here's my code. How to resolve this Warning. The page actually works on my local environment, but doesn't parse when uploaded to dev.

warning
 
  <?php 
    define('DB_IP', 'localhost');                   // MySQL Server
    define('DB_USERNAME', 'xxx');       	        //database username
    define('DB_PASSWORD', 'xxx');       		//database password
    define('DB_DATABASE', 'navigator_data');        //database
    
    class test_object   // proxy for web service object
    {
        public $contractVehicle = array(
            0=>'ITSchedule70',
            1=>'ITCommodityProgram',
    	2=>'Army CHESS',
    	3=>'NASA SEWP'
        );
    
        function get_contract()
        {
            return $this->contractVehicle;
        }
    }
    
    $var = new test_object(); // the variable get back from webservice
    
    $connection = mysqli_connect(DB_IP,DB_USERNAME,DB_PASSWORD,DB_DATABASE); // connection to navigator_data
    
    $qry_nav_data = "SELECT * FROM contract_vehicle"; // formulate the SQL query
    
    $result = mysqli_query($connection, $qry_nav_data); // execute the query
    
    // display results in HTML table
    echo "<table border='1'>
    <tr>
    <th>contract_vehicle_id</th>
    <th>vehicle_name</th>
    </tr>";
    
    while($row = mysqli_fetch_array($result)) {
      echo "<tr>";
      echo "<td>" . $row['contract_vehicle_id'] . "</td>";
      echo "<td>" . $row['vehicle_name'] . "</td>";
      echo "</tr>";
    }
    echo "</table>";
    
    mysqli_close($connection);
    ?>

Open in new window

0
Comment
Question by:sandshakimi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
Radek Baranowski earned 167 total points
ID: 40323095
From http://php.net/manual/en/mysqli.query.php:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

that means that probably your query was unsuccessful and $result = false

try to see what's in $result with
var_dump($result);

in your code.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 167 total points
ID: 40323171
The warning is a symptom of a query failure.  There are ways to see the query errors.  Learn about this function:
http://www.php.net/manual/en/mysqli.error.php

This article is not short, nor simple, but it's the sort of thing a professional programmer would be required to understand.   Please read it over and post back if you have any further questions.  It shows how to use the MySQL extensions and maps the familiar but obsolete MySQL extension onto MySQLi and PDO.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 166 total points
ID: 40323237
I would guess that the dev server does not have the contract_vehicle table, or that your user credentials on dev for MySQL don't have access to the database or table. One of those, but probably the first one.

That would result in a failed query, like the previous two gentlemen have said.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question