Jump to content

mysql_fetch_array(): supplied argument is not a valid MySQL result resource?


marts555

Recommended Posts

Hello!

I'm kinda new to PHP so excuse me for bothering you all with such a newbie-like question and code...

Well you'll understand what i want with this code so i wont bother you about explaining it but i wonder why do i get "mysql_fetch_array(): supplied argument is not a valid MySQL result resource" error when i try to open it with a browser.

This is the code:

  <?php

  $d = date('Y.m.d');

  echo $d;

  $con = mysql_connect("localhost","root","");

if (!$con)

  {

die('Could not connect: ' . mysql_error());

  }

    mysql_select_db("skolnieki",$con);

$query="SELECT DISTINCT skolnieki WHERE date=$d";

$result=mysql_query($query,$con);

    while($row = mysql_fetch_array($result))

  {

echo $row['name'];

echo "<br>";

}

  ?>

 

So can anyone explain what is wrong with this code since i don't see the problem but WAMP 2.0 says the error? ^^

And yes i've made sure that MySQL DB has the same date in it - "2009.06.04" i believe it is as text but then again i inserted it using MySQL consol from .txt file made in MExcel so i just guess it is as text.

Just in case - there is a "name" column with a name XD

 

Thanks,

Marts555

That error means your query isn't valid.  You're not telling it which table to select from.

 

$query="SELECT DISTINCT skolnieki WHERE date=$d";

should be

$query="SELECT DISTINCT skolnieki from YourTableName WHERE date=$d";

Archived

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

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