473,241 Members | 1,385 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Nested mySQL queries create issue with validity of result index?

Hi all,
I am iterating through a result set to generate a second set of queries but
no matter what I do I get the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

even though if I echo the query to the browser and cut and paste it into the
command line I get valid results.

Do I have to store the first result in an array before doing the second set?

TIA,
jg

while ($i < mysql_num_rows($result)) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
while ($j < mysql_num_rows($PIDresult)) {
$PIDs[$id]['PID']['Comments'] = mysql_result($PIDresult, $j,
'Comments');
$j++;
}
$i++;
}
}
Jul 16 '05 #1
6 3648
jerrygarciuh <de*****@no.spam.nolaflash.com> wrote:
Hi all,
I am iterating through a result set to generate a second set of queries
but no matter what I do I get the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource
Hi Jerry,

You should call mysql_num_rows() only once.

while ($i < mysql_num_rows($result)) {
$NumRows_1 = mysql_num_rows($result);
while ($i < $NumRows_1) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
while ($j < mysql_num_rows($PIDresult)) {


$NumRows_2 = mysql_num_rows($PIDresult)
while ($j < $NumRows_2) {

[snip]

HTH;
JOn
Jul 16 '05 #2
Jon,

Thanks for the reply. Calling mysql_num_rows in the way you suggest still
produces the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

My adjusted code is below. I am thinking the Good way must be to store what
I need in a throwaway array and not nest the queries.
Thanks for any advice!

jg

foreach ($clients as $id => $client) {
$i = 0;
$result = mysql_query("SELECT PID, Name FROM projects WHERE ID = '$id'");
$NumRows_1 = mysql_num_rows($result);
while ($i < $NumRows_1) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
$NumRows_2 = mysql_num_rows($PIDresult);
while ($j < $NumRows_2) {
$PIDs[$id]['PID']['Comments'] = mysql_result($PIDresult, $j,
'Comments');
//make an array of Session info and add to $PIDs
$j++;
}
$i++;
}
}

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:bj************@ID-175424.news.uni-berlin.de...
jerrygarciuh <de*****@no.spam.nolaflash.com> wrote:
Hi all,
I am iterating through a result set to generate a second set of queries
but no matter what I do I get the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource


Hi Jerry,

You should call mysql_num_rows() only once.

while ($i < mysql_num_rows($result)) {


$NumRows_1 = mysql_num_rows($result);
while ($i < $NumRows_1) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
while ($j < mysql_num_rows($PIDresult)) {


$NumRows_2 = mysql_num_rows($PIDresult)
while ($j < $NumRows_2) {

[snip]

HTH;
JOn

Jul 16 '05 #3
jerrygarciuh <de*****@no.spam.nolaflash.com> wrote:
Jon,

Thanks for the reply. Calling mysql_num_rows in the way you suggest still
produces the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

My adjusted code is below. I am thinking the Good way must be to store
what I need in a throwaway array and not nest the queries.

foreach ($clients as $id => $client) {
$i = 0;
$result = mysql_query("SELECT PID, Name FROM projects WHERE ID =
'$id'"); $NumRows_1 = mysql_num_rows($result);


Then the error message means your query fails and there is no valid result
set. Try this to check on the SQL error:

$sql = "SELECT PID, Name FROM projects WHERE ID = '$id'";
$result = mysql_query($sql) or die (mysql_error()."".$sql);

HTH;
JOn
Jul 16 '05 #4
Jon,

Well a very odd thing happened. I had been echoing the query and running it
from the command line and getting results but I went ahead and changed to
your format of setting up the query string as a scalar and inserting it as
such and lo and behold the error disappeared.

Thanks!

jg
"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:bj************@ID-175424.news.uni-berlin.de...
jerrygarciuh <de*****@no.spam.nolaflash.com> wrote:
Jon,

Thanks for the reply. Calling mysql_num_rows in the way you suggest still produces the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

My adjusted code is below. I am thinking the Good way must be to store
what I need in a throwaway array and not nest the queries.

foreach ($clients as $id => $client) {
$i = 0;
$result = mysql_query("SELECT PID, Name FROM projects WHERE ID =
'$id'"); $NumRows_1 = mysql_num_rows($result);


Then the error message means your query fails and there is no valid result
set. Try this to check on the SQL error:

$sql = "SELECT PID, Name FROM projects WHERE ID = '$id'";
$result = mysql_query($sql) or die (mysql_error()."".$sql);

HTH;
JOn

Jul 16 '05 #5
On Sun, 7 Sep 2003 20:50:58 -0500, "jerrygarciuh"
<de*****@no.spam.nolaflash.com> wrote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource $PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());


You're missing a mysql_query() around the SQL string.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #6
OMG, laughing very hard at myself just now.

Thanks!

jg

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:du********************************@4ax.com...
On Sun, 7 Sep 2003 20:50:58 -0500, "jerrygarciuh"
<de*****@no.spam.nolaflash.com> wrote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());


You're missing a mysql_query() around the SQL string.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

Jul 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: StinkFinger | last post by:
All, I am in the process of tweaking and tuning my PHP scripts, and am starting to look in tweaking my indexes in my MySQL tables. I have found many, many articles on the topic and have applied...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
6
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid...
39
by: Mairhtin O'Feannag | last post by:
Hello, I have a client (customer) who asked the question : "Why would I buy and use UDB, when MySql is free?" I had to say I was stunned. I have no experience with MySql, so I was left sort...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
1
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.