473,473 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

passing a parameter to a function

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
9 1525
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
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
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
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
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
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
>
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: diffuser78 | last post by:
I wrote a small app in wxPython using wxGlade as designer tool. wxGlade brings and writes a lot of code by itself and thats where my confusion started. Its about parameter passing. Here is my...
2
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
0
by: amazon | last post by:
I have web service that acceping following parameters.. postev.PostEvent(authentication as ws.authentication, name as string,id as string, exdate as date, parameter() as ws.nameparametervaluepair...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.