Jump to content

Archived

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

jeva39

mysql_fetch_array Problem...

Recommended Posts

Hello

I use this simple code to try something in my Web Server (Using PHP 4.4 and mySql 4.1):


[code]<?php
$con = mysql_connect("localhost", "username", "pass");
mysql_select_db("jv");

$query  = "SELECT tema, ritmo FROM temas where ritmo='BALADA' order by tema";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_NUM)) // Line 8
{
    echo "Tema : {$row[0]} " . " Ritmo : {$row[1]} <br>";
}

mysql_close($con);

?>[/code]

But I receive this error:

[color=red]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhosts\prolatin.com\httpdocs\php\jv_mysql.php on line 8 [/color]


The Database don't have problem. Please do you can help me what is wrong?

In my computer all run OK.

Thanks in advanced....

Share this post


Link to post
Share on other sites
try this...
[code=php:0]<?php
$con = mysql_connect("localhost", "username", "pass");
mysql_select_db("jv");

$result = mysql_query("SELECT tema, ritmo FROM temas where ritmo='BALADA' order by tema") or die('Result Error: '.mysql_error().'');

while($row = mysql_fetch_array($result, MYSQL_NUM)) // Line 8
{
    echo "Tema : {$row[0]} " . " Ritmo : {$row[1]} <br>";
}

mysql_close($con);

?>[/code]

Share this post


Link to post
Share on other sites
Not a valid result resource means the query returned no rows or failed for another reason.  You should ideally be checking at each stage to make sure it's successful before performing the next step.

Dest

Share this post


Link to post
Share on other sites

×

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.