By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

passing a parameter to a function

P: n/a
I'm getting the error message that the parameter passed to the
function is not a valid resource. The parameter is $result and it is
from a query in a switch statement. What do I have to do to get it to
accept it?
tia,

function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){

$header .= mysql_field_name($result, $i) ."\t";
}
$header .= "\n";

return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
Sep 2 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
JRough wrote:
I'm getting the error message that the parameter passed to the
function is not a valid resource. The parameter is $result and it is
from a query in a switch statement. What do I have to do to get it to
accept it?
tia,

function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){

$header .= mysql_field_name($result, $i) ."\t";
}
$header .= "\n";

return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
You didn't show the functions you're calling to get $result - but your
query failed.

Always check the result of a query - never assume it worked. If the
result is false, the query failed. You then need to find out why your
query failed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 2 '08 #2

P: n/a
On Sep 2, 3:47*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I'm getting the error message that the parameter passed to the
function is not a valid resource. *The parameter is $result and it is
from a query in a switch statement. *What do I have to do to get it to
accept it?
tia,
function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){
* *$header .= mysql_field_name($result, $i) ."\t";
* *}
* * $header .= "\n";
return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
* * * * * *case 'internal':
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* * * * * *case 'owner':
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* * * * * *default:
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* *}

You didn't show the functions you're calling to get $result - but your
query failed.

Always check the result of a query - never assume it worked. *If the
result is false, the query failed. *You then need to find out why your
query failed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I ran the query and it does work but it has to have a $id. Which I
think is at the beginning of the
page in the validate login step. The $order_by and $days parameters
are already set. I wonder if the query is
not picking up the $id variable?
Here is my function call. I don't know if it is right or not. I put
the print_r to debug it.
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}

thanks,
Validate_login("idle_cars.php?id=".$id);
Sep 3 '08 #3

P: n/a
JRough wrote:
On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>JRough wrote:
>>I'm getting the error message that the parameter passed to the
function is not a valid resource. The parameter is $result and it is
from a query in a switch statement. What do I have to do to get it to
accept it?
tia,
function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){
$header .= mysql_field_name($result, $i) ."\t";
}
$header .= "\n";
return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
You didn't show the functions you're calling to get $result - but your
query failed.

Always check the result of a query - never assume it worked. If the
result is false, the query failed. You then need to find out why your
query failed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

I ran the query and it does work but it has to have a $id. Which I
think is at the beginning of the
page in the validate login step. The $order_by and $days parameters
are already set. I wonder if the query is
not picking up the $id variable?
Here is my function call. I don't know if it is right or not. I put
the print_r to debug it.
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}

thanks,
Validate_login("idle_cars.php?id=".$id);
Your query is failing. That much is obvious.

As I said above - ALWAYS CHECK THE RESULT OF A QUERY - NEVER ASSUME IT
WORKED. IF THE RESULT IS false, THE QUERY FAILED. YOU NEED THEN TO
FIND OUT WHY YOUR QUERY FAILED.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 3 '08 #4

P: n/a
JRough wrote:
On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>JRough wrote:
>>I'm getting the error message that the parameter passed to the
function is not a valid resource. The parameter is $result and it is
from a query in a switch statement. What do I have to do to get it to
accept it?
tia,
function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){
$header .= mysql_field_name($result, $i) ."\t";
}
$header .= "\n";
return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
You didn't show the functions you're calling to get $result - but your
query failed.

Always check the result of a query - never assume it worked. If the
result is false, the query failed. You then need to find out why your
query failed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

I ran the query and it does work but it has to have a $id. Which I
think is at the beginning of the
page in the validate login step. The $order_by and $days parameters
are already set. I wonder if the query is
not picking up the $id variable?
Here is my function call. I don't know if it is right or not. I put
the print_r to debug it.
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}

thanks,
Validate_login("idle_cars.php?id=".$id);
Your error message is screaming at you that you code to obtain the
$result is bad before it even gets used by the function, not the
function that uses $result.

You need to show your code used to obtain the $result if you want help,
or we are just throwing mud at the wall.

You are trying to find out why your bulb burned out and all the time
your light switch is off.

Scotty
Sep 3 '08 #5

P: n/a
On Sep 2, 8:13*pm, FutureShock <futuresh...@att.netwrote:
JRough wrote:
On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I'm getting the error message that the parameter passed to the
function is not a valid resource. *The parameter is $result and it is
from a query in a switch statement. *What do I have to do to get itto
accept it?
tia,
function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){
* *$header .= mysql_field_name($result, $i) ."\t";
* *}
* * $header .= "\n";
return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
* * * * * *case 'internal':
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* * * * * *case 'owner':
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* * * * * *default:
* * * * * * * * * *$headers = GetHeaders($file_name);
* * * * * * * * * *$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
* * * * * * * * * *$lease_row = false;
* * * * * * * * * *break;
* *}
You didn't show the functions you're calling to get $result - but your
query failed.
Always check the result of a query - never assume it worked. *If the
result is false, the query failed. *You then need to find out why your
query failed.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I ran the query and it does work but it has to have a $id. *Which I
think is at the beginning of the
page in the validate login step. *The $order_by and $days parameters
are already set. *I wonder if the query is
not picking up the $id variable?
Here is my function call. *I don't know if it is right or not. *I put
the print_r to debug it.
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}
thanks,
Validate_login("idle_cars.php?id=".$id);

Your error message is screaming at you that you code to obtain the
$result is bad before it even gets used by the function, not the
function that uses $result.

You need to show your code used to obtain the $result if you want help,
or we are just throwing mud at the wall.

You are trying to find out why your bulb burned out and all the time
your light switch is off.

Scotty
I don't understand why $result doesn't work because the page works
without the function?
Validate_login("idle_cars.php?id=".$id);

$days = 3;
$TPL_carnumbers = "<table>";

if(empty($order_by)){
$order_by = 'sighting_date_asc';
}

# GET CARS FOR GIVEN PARAMETER?
if(empty($id)){
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS";
$file_name = "idle_cars.php?";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
case 'owner':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days_owner($days,CLM_order_by($order_b y));
$lease_row = true;
break;
case 'customer':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_customer($days,CLM_order_by($orde r_by));
$lease_row = false;
break;
default:
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
}
}else{
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
".GetLeaseCompName($id);
$file_name = "idle_cars.php?id=".$id."&";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
}
$TPL_carnumbers.= $headers;

if ($_POST['assign']!='Open in Excel'){
if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);
}else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($lease_row,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";

}else{
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}
include "footer.php";
Sep 3 '08 #6

P: n/a
JRough wrote:
On Sep 2, 8:13 pm, FutureShock <futuresh...@att.netwrote:

I don't understand why $result doesn't work because the page works
without the function?
Validate_login("idle_cars.php?id=".$id);
(lots of stuff trimmed)

All you're doing is setting $result to a string. You are not making a
mysql_query call with the string, so you will not have a mysql result in
the variable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 3 '08 #7

P: n/a
>
I don't understand why $result doesn't work because the page works
without the function?
Validate_login("idle_cars.php?id=".$id);

$days = 3;
$TPL_carnumbers = "<table>";

if(empty($order_by)){
$order_by = 'sighting_date_asc';
}

# GET CARS FOR GIVEN PARAMETER?
if(empty($id)){
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS";
$file_name = "idle_cars.php?";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
case 'owner':
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days_owner($days,CLM_order_by($order_b y));
$lease_row = true;
break;
case 'customer':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_customer($days,CLM_order_by($orde r_by));
$lease_row = false;
break;
default:
$headers = GetLeaseHeaders($file_name);
$result = SELECT_idle_days($days,CLM_order_by($order_by));
$lease_row = true;
break;
}
}else{
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
".GetLeaseCompName($id);
$file_name = "idle_cars.php?id=".$id."&";
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
}
$TPL_carnumbers.= $headers;

if ($_POST['assign']!='Open in Excel'){
if(mysql_numrows($result)==0){
$TPL_carnumbers.= GetNoCarsMsg($th);
}else{
while ($row = mysql_fetch_assoc($result)){
$TPL_carnumbers.=MakeSighting($lease_row,$row);
}
}

$TPL_carnumbers.="</table>";

include "header.php";
include $template_path."template_carlist.html";
include "footer.php";

}else{
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}
include "footer.php";
*SIGH*

Of course it will work in this code, you are not expecting $result to be
anything, you are in this case setting it. '$result = xxxxx'.

In the function you where using $result as a parameter to
mysql_num_fields($result) in which case it needed to be a MySQL resource.

The best way to debug any code is to blackbox test it.

Write a 'SIMPLE' output function to test the input variables. ALWAYS
confirm your data is correct BEFORE trying to use it.

If you had error checking on your SQL code you may have caught the problem:

$query = "SELECT * FROM $table";
if(!$result = mysql_query($query)) {
echo "Error on query: ".$query";
}

If $result gets past this, then most often it is a RESOURCE.

But hey man, if your sql query is that top secret that you do not want
to post it for help, maybe contact the CIA, they know all your secrets
anyhow, we can't help you any more.

Scotty
Sep 3 '08 #8

P: n/a
JRough wrote:
On Sep 2, 8:13 pm, FutureShock <futuresh...@att.netwrote:
>JRough wrote:
>>On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
JRough wrote:
I'm getting the error message that the parameter passed to the
function is not a valid resource. The parameter is $result and it is
from a query in a switch statement. What do I have to do to get it to
accept it?
tia,
function MakeXclHeader($result){
$fields = mysql_num_fields($result);
for ($i = 0; $i < $fields; $i++){
$header .= mysql_field_name($result, $i) ."\t";
}
$header .= "\n";
return 1;
}
----------------------------
switch ($_SESSION["LMS_USER_DESC"]){
case 'internal':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease_owner($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
default:
$headers = GetHeaders($file_name);
$result = SELECT_idle_days_lease($id,
$days,CLM_order_by($order_by));
$lease_row = false;
break;
}
You didn't show the functions you're calling to get $result - but your
query failed.
Always check the result of a query - never assume it worked. If the
result is false, the query failed. You then need to find out why your
query failed.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I ran the query and it does work but it has to have a $id. Which I
think is at the beginning of the
page in the validate login step. The $order_by and $days parameters
are already set. I wonder if the query is
not picking up the $id variable?
Here is my function call. I don't know if it is right or not. I put
the print_r to debug it.
$xcl_header= MakeXclHeader($header);
print_r($xcl_header);
}
thanks,
Validate_login("idle_cars.php?id=".$id);
Your error message is screaming at you that you code to obtain the
$result is bad before it even gets used by the function, not the
function that uses $result.

You need to show your code used to obtain the $result if you want help,
or we are just throwing mud at the wall.

You are trying to find out why your bulb burned out and all the time
your light switch is off.
I don't understand why $result doesn't work because the page works
without the function?
<code snipped>

I'm fresh out of magic crystal balls that let me see into the source
code of people's APIs when not posted. Also, try trimming down the
code posted to only what's relevant.

However, your query functions, like "SELECT_idle_days", and its ilk,
are not returning valid query resources (a deduction made evident by
the error you reported having). If you want to fix it, find out what's
wrong with your queries, or what's wrong with your API in general.

--
Curtis
Sep 4 '08 #9

P: n/a
Curtis wrote:
<snip>
>
<code snipped>

I'm fresh out of magic crystal balls that let me see into the source
code of people's APIs when not posted. Also, try trimming down the code
posted to only what's relevant.

However, your query functions, like "SELECT_idle_days", and its ilk, are
not returning valid query resources (a deduction made evident by the
error you reported having). If you want to fix it, find out what's wrong
with your queries, or what's wrong with your API in general.

--
Curtis
Curtis, I think you need Top-Secret or better clearance to view that
code. I need to go into the Crystal Ball repair business.

Scotty
Sep 4 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.