problem with select count(*)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    problem with select count(*)

    Hi,

    I have a problem with this query:


    $link = mysql_connect(" localhost", "root", "pw");
    $dbsel = mysql_select_db ('mydb', $link);
    $lol='bibi';

    $sql = "select count(*) as totuur from studres where where dag>= curdate()
    AND logon='" . $lol . "'";
    $result = mysql_query($sq l);
    $row = mysql_fetch_fie ld($result,0);
    // J'ai essayé avec: $row = mysql_fetch_row ($result);
    $totu=$row[0];


    The error is on line: $row = mysql_fetch_fie ld($result,0):
    Warning: mysql_fetch_fie ld(): supplied argument is not a valid MySQL result
    resource in c:\Inetpub\wwwr oot\myfile.php on line 74


    Thanks
    Ben


  • Kimmo Laine

    #2
    Re: problem with select count(*)

    "Ben" <sdvs@qcsq> wrote in message
    news:M8ednbrca5 ajADveRVnygQ@sc arlet.biz...[color=blue]
    > Hi,
    >
    > I have a problem with this query:
    >
    >
    > $link = mysql_connect(" localhost", "root", "pw");
    > $dbsel = mysql_select_db ('mydb', $link);
    > $lol='bibi';
    >
    > $sql = "select count(*) as totuur from studres where where dag>= curdate()
    > AND logon='" . $lol . "'";[/color]


    You have WHERE twice in "...from studres where where dag...", try what
    happens if you remove the extra where. This is one of the reasons why sql
    keywords should be written in CAPITAL letters. It's easier to spot the error
    if you write:
    "SELECT COUNT(*) AS totuur FROM studres WHERE WHERE dag>= CURDATE() AND
    logon='$lol'"

    --
    "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
    antaatulla.sika nautaa@gmail.co m.NOSPAM.invalid


    Comment

    • Jerry Stuckle

      #3
      Re: problem with select count(*)

      Kimmo Laine wrote:[color=blue]
      > "Ben" <sdvs@qcsq> wrote in message
      > news:M8ednbrca5 ajADveRVnygQ@sc arlet.biz...
      >[color=green]
      >>Hi,
      >>
      >>I have a problem with this query:
      >>
      >>
      >>$link = mysql_connect(" localhost", "root", "pw");
      >>$dbsel = mysql_select_db ('mydb', $link);
      >>$lol='bibi' ;
      >>
      >>$sql = "select count(*) as totuur from studres where where dag>= curdate()
      >>AND logon='" . $lol . "'";[/color]
      >
      >
      >
      > You have WHERE twice in "...from studres where where dag...", try what
      > happens if you remove the extra where. This is one of the reasons why sql
      > keywords should be written in CAPITAL letters. It's easier to spot the error
      > if you write:
      > "SELECT COUNT(*) AS totuur FROM studres WHERE WHERE dag>= CURDATE() AND
      > logon='$lol'"
      >[/color]

      And if you would have checked the result of the mysql_query() call, you
      would have found your problem.

      $result = mysql_query($sq l);
      if ($result) {
      $row = mysql_fetch_fie ld($result,0);
      // J'ai essayé avec: $row = mysql_fetch_row ($result);
      $totu=$row[0];
      }
      else
      echo "MySQL error: " . mysql_error();


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...