MySql and PHP mysql_fetch_array($result) - function

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

    #1

    MySql and PHP mysql_fetch_array($result) - function

    In the part of code:

    $polecenie = "SELECT osoby.Id ,osoby.Imie ,
    osoby.Nazwisko, osoby.Tytul,oso by.Email,adresp raca.Adres AS ap,
    adrespraca.KodP oczt AS
    KodP,adrespraca .NazwaInstytucj i,adrespraca.Mi asto AS MiastP,
    adrespraca.Woje wodztwo AS wojPr,adresprac a.NrTelefonu As
    TelP,adresdom.A dres,adresdom.K odPoczt,
    adresdom.Miasto ,adresdom.Wojew odztwo,adresdom .NrTelefonu,stu dia.Od,studia.D o,
    studia.Kierunek ,studia.MiejscS tud,studia.IdUc zelni,uczelnia. NazwaUczelni
    as nazwUcz FROM osoby
    INNER JOIN adrespraca ON osoby.Id = adrespraca.User Id
    INNER JOIN adresdom ON
    osoby.Id = adresdom.UserId INNER JOIN studia ON osoby.Id
    = studia.IdStuden ta INNER JOIN
    uczelnia ON uczelnia.IdUcze lni = studia.IdUczeln i INNER
    JOIN
    wojew ON adrespraca.Woje wodztwo = wojew.IdWoj WHERE
    osoby.imie='Joh n' ";

    $polaczenie = mysql_connect(" 127.0.0.1", $useName, $pass);
    $baza = "sample";
    mysql_select_db ($baza, $polaczenie);

    $result = mysql_query($po lecenie,$polacz enie);

    while($wiersz = mysql_fetch_arr ay($result)){

    //here I print the received data with print
    ($wiersz["Column_nam e"]);

    }



    So the problem is , that mysql_query() - function returns "Resource id
    #2" as it should and after that when I call mysql_fetch_arr ay($result)
    it returns nothing - every time I try to receive less than 3 results.

    Variable $polaczenie is just a sample in the code, usually it is
    generated by function which for sure works properly. When "SELECT"
    statement should return 3 or more results, it prints everything
    staring from the 3rd. When I paste the generated "Select" statement
    into the command line im MySql interface it works like it should.

    I have no idea where the problem is, I would be grateful for replies.

    Konrad
  • Gert

    #2
    Re: MySql and PHP mysql_fetch_arr ay($result) - function

    > $polaczenie = mysql_connect(" 127.0.0.1", $useName, $pass);[color=blue]
    > $baza = "sample";
    > mysql_select_db ($baza, $polaczenie);
    >
    > $result = mysql_query($po lecenie,$polacz enie);[/color]

    //Here try the following:

    echo "Number of rows in query: " . mysql_num_rows( $result) . "<br>";

    What does it tell you???

    Greetings,

    Gert.


    Comment

    • Ian.H

      #3
      Re: MySql and PHP mysql_fetch_arr ay($result) - function

      On 13 Sep 2004 02:58:32 -0700, konio@eranet.pl (Konrad) wrote:


      [ snip ]

      [color=blue]
      >$result = mysql_query($po lecenie,$polacz enie);
      >
      >while($wiers z = mysql_fetch_arr ay($result)){
      >
      > //here I print the received data with print
      >($wiersz["Column_nam e"]);
      >
      >
      >So the problem is , that mysql_query() - function returns "Resource id
      >#2" as it should and after that when I call mysql_fetch_arr ay($result)
      >it returns nothing - every time I try to receive less than 3 results.
      >
      >Variable $polaczenie is just a sample in the code, usually it is
      >generated by function which for sure works properly. When "SELECT"
      >statement should return 3 or more results, it prints everything
      >staring from the 3rd. When I paste the generated "Select" statement
      >into the command line im MySql interface it works like it should.
      >
      >I have no idea where the problem is, I would be grateful for replies.[/color]


      Obviously.. because you have zero error checking.


      $result = mysql_query($fo o, $bar);
      if (is_resource($r esult)) {
      if (mysql_num_rows ($result) > 0) {
      /* do stuff with results... */
      } else {
      die('Zero rows retrieved');
      } else {
      die(mysql_error ());
      }


      That should at least point out the problem to you.


      HTH.



      Regards,

      Ian

      --
      Ian.H
      digiServ Network
      London, UK

      Comment

      • Konrad

        #4
        Re: MySql and PHP mysql_fetch_arr ay($result) - function

        It returns the factual amount of rows, but mysql_fetch_row ($result) &
        mysql_fetch_arr ay($result) returns nothing. It's really weird to me.

        Konrad

        Comment

        • Ian.H

          #5
          Re: MySql and PHP mysql_fetch_arr ay($result) - function

          On 14 Sep 2004 00:36:54 -0700, konio@eranet.pl (Konrad) wrote:
          [color=blue]
          >It returns the factual amount of rows, but mysql_fetch_row ($result) &
          >mysql_fetch_ar ray($result) returns nothing. It's really weird to me.
          >
          >Konrad[/color]



          What does?

          Talking to yourself is the first sign of madness ;)



          Regards,

          Ian

          --
          Ian.H
          digiServ Network
          London, UK

          Comment

          Working...