469,632 Members | 1,730 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

MySql and PHP mysql_fetch_array($result) - function

In the part of code:

$polecenie = "SELECT osoby.Id ,osoby.Imie ,
osoby.Nazwisko,osoby.Tytul,osoby.Email,adrespraca. Adres AS ap,
adrespraca.KodPoczt AS
KodP,adrespraca.NazwaInstytucji,adrespraca.Miasto AS MiastP,
adrespraca.Wojewodztwo AS wojPr,adrespraca.NrTelefonu As
TelP,adresdom.Adres,adresdom.KodPoczt,
adresdom.Miasto,adresdom.Wojewodztwo,adresdom.NrTe lefonu,studia.Od,studia.Do,
studia.Kierunek,studia.MiejscStud,studia.IdUczelni ,uczelnia.NazwaUczelni
as nazwUcz FROM osoby
INNER JOIN adrespraca ON osoby.Id = adrespraca.UserId
INNER JOIN adresdom ON
osoby.Id = adresdom.UserId INNER JOIN studia ON osoby.Id
= studia.IdStudenta INNER JOIN
uczelnia ON uczelnia.IdUczelni = studia.IdUczelni INNER
JOIN
wojew ON adrespraca.Wojewodztwo = wojew.IdWoj WHERE
osoby.imie='John' ";

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

$result = mysql_query($polecenie,$polaczenie);

while($wiersz = mysql_fetch_array($result)){

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

}

So the problem is , that mysql_query() - function returns "Resource id
#2" as it should and after that when I call mysql_fetch_array($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
Jul 17 '05 #1
4 5241
> $polaczenie = mysql_connect("127.0.0.1", $useName, $pass);
$baza = "sample";
mysql_select_db($baza, $polaczenie);

$result = mysql_query($polecenie,$polaczenie);


//Here try the following:

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

What does it tell you???

Greetings,

Gert.
Jul 17 '05 #2
On 13 Sep 2004 02:58:32 -0700, ko***@eranet.pl (Konrad) wrote:
[ snip ]

$result = mysql_query($polecenie,$polaczenie);

while($wiersz = mysql_fetch_array($result)){

//here I print the received data with print
($wiersz["Column_name"]);
So the problem is , that mysql_query() - function returns "Resource id
#2" as it should and after that when I call mysql_fetch_array($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.

Obviously.. because you have zero error checking.
$result = mysql_query($foo, $bar);
if (is_resource($result)) {
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
http://digiserv.net/
Jul 17 '05 #3
It returns the factual amount of rows, but mysql_fetch_row($result) &
mysql_fetch_array($result) returns nothing. It's really weird to me.

Konrad
Jul 17 '05 #4
On 14 Sep 2004 00:36:54 -0700, ko***@eranet.pl (Konrad) wrote:
It returns the factual amount of rows, but mysql_fetch_row($result) &
mysql_fetch_array($result) returns nothing. It's really weird to me.

Konrad


What does?

Talking to yourself is the first sign of madness ;)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by frizzle | last post: by
reply views Thread by Marcel Molenaar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.