New and odd Select problems

Hi,

I’ve created a menu, a drop down menu. It fetches data from an Mysql databse in date order.
When I put the code on my webserver (hosting) it works beautifully.

When I try it locally on my WAMP server it produces an error.
Connection to database works fine so I show you only the problematic part of the code:

    $result = "SELECT * FROM node ORDER BY `created` DESC LIMIT 10";
    $rows = mysqli_query($conn, $result);
    {
    while($row = mysqli_fetch_assoc($rows))
    {
  echo "<p>" . "<a href=\'las_artikel?phpid=' . $row[0] . '\'>" . $row['title'] . "</a>  " . "<hr>" . "</p>";

    	}

    }

Wamt generates the following error message: ’ Notice: Undefined offset: 0 in C:\wamp64\www\bootstrapsite\index.php on line 33.
Now, line 33 is the line that begins with ‘echo’.
What shall I make of this? All input is appreciated.

Well, i have no idea how this code would work correctly on your webserver.

Unless you have a column in your table called 0, $row[0] does not exist in an associative array. (and even if you did, i’m not sure that php would find $row[0] and not expect you to look for $row["0"]…)

Try adding the following to display query results:

while($row = mysqli_fetch_assoc($rows))
 {
// add this line - pre adds line feeds and die stops execution 
echo ‘<pre>’; print_r($row); die:

I assume the error reporting on the remote web server is set to not display errors and possibly error_reporting is set to 0 or no errors.

There is a good chance error_reporting is active and errors and warnings will be logged.

Error reporting locally is usually set to maximum E_ALL and also to show all errors - ini_set(‘display_errors’,’true’);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.