MySql and PHP "Using WHERE in a SELECT statememt"

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

    MySql and PHP "Using WHERE in a SELECT statememt"

    i have a basic php file that is trying to select information from a
    mysql database.

    echo "<br>";
    include("dbConn ect.inc");
    $query = "SELECT * FROM client";
    $result = mysql_query($qu ery) or die("no select");
    $row = mysql_fetch_arr ay($result,MYSQ L_ASSOC);
    while ($row = mysql_fetch_arr ay($result))
    {
    extract($row);
    echo "Welcome ".$fName." ".$lName." - ".$deptID."<br> ";
    }

    this works, but it doesnt return the first record from the table. when
    i add a WHERE statement, nothing is returned. im using phpMyAdmin to
    administer mysql. i can get all of the rows from the client table when
    i browse from phpMyAdmin.

    also, i can use PEAR database abstraction layer and it retrieves all
    records and WHERE works in the select. is there a mysql or php setting
    im missing?

    im using mysql 4.01 and php 4.3
  • Pedro

    #2
    Re: MySql and PHP &quot;Using WHERE in a SELECT statememt&quot;

    Ric wrote:[color=blue]
    > i have a basic php file that is trying to select information from a
    > mysql database.
    >
    > echo "<br>";
    > include("dbConn ect.inc");
    > $query = "SELECT * FROM client";
    > $result = mysql_query($qu ery) or die("no select");
    > $row = mysql_fetch_arr ay($result,MYSQ L_ASSOC);[/color]
    ### get the *FIRST* record into $row
    [color=blue]
    > while ($row = mysql_fetch_arr ay($result))[/color]
    ### get the *SECOND* (or 3rd, 4th, ...) record into $row
    [color=blue]
    > {
    > extract($row);
    > echo "Welcome ".$fName." ".$lName." - ".$deptID."<br> ";
    > }
    >
    > this works, but it doesnt return the first record from the table. when
    > i add a WHERE statement, nothing is returned.[/color]

    remove the first mysql_fetch_arr ay() and it should be ok


    HTH

    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.

    Comment

    • Ric

      #3
      Re: MySql and PHP &quot;Using WHERE in a SELECT statememt&quot;

      thx. that worked. i really appreciate the help.

      Pedro <hexkid@hotpop. com> wrote in message news:<bm20hk$gq 038$1@ID-203069.news.uni-berlin.de>...[color=blue]
      > Ric wrote:[color=green]
      > > i have a basic php file that is trying to select information from a
      > > mysql database.
      > >
      > > echo "<br>";
      > > include("dbConn ect.inc");
      > > $query = "SELECT * FROM client";
      > > $result = mysql_query($qu ery) or die("no select");
      > > $row = mysql_fetch_arr ay($result,MYSQ L_ASSOC);[/color]
      > ### get the *FIRST* record into $row
      >[color=green]
      > > while ($row = mysql_fetch_arr ay($result))[/color]
      > ### get the *SECOND* (or 3rd, 4th, ...) record into $row
      >[color=green]
      > > {
      > > extract($row);
      > > echo "Welcome ".$fName." ".$lName." - ".$deptID."<br> ";
      > > }
      > >
      > > this works, but it doesnt return the first record from the table. when
      > > i add a WHERE statement, nothing is returned.[/color]
      >
      > remove the first mysql_fetch_arr ay() and it should be ok
      >
      >
      > HTH[/color]

      Comment

      Working...