|  | passing a parameter to a function |  | |
| | | JRough |  |
| Posted: Tue Sep 02, 2008 10:38 pm Post subject: 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; } |
| |
| | | Jerry Stuckle |  |
| Posted: Tue Sep 02, 2008 10:38 pm Post subject: Re: passing a parameter to a function |  |
| |  | |
JRough wrote:
| Quote: | 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. jstucklex@attglobal.net ================== |
| |
| | | Jerry Stuckle |  |
| Posted: Tue Sep 02, 2008 11:12 pm Post subject: Re: passing a parameter to a function |  |
| |  | |
JRough wrote:
| Quote: | On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: 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. jstucklex@attglobal.net ================== |
| |
| | | JRough |  |
| Posted: Wed Sep 03, 2008 12:37 am Post subject: Re: passing a parameter to a function |  |
| |  | |
On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
| Quote: | 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); |
| |
| | | FutureShock |  |
| Posted: Wed Sep 03, 2008 1:13 am Post subject: Re: passing a parameter to a function |  |
| |  | |
JRough wrote:
| Quote: | On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: 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 |
| |
| | | Jerry Stuckle |  |
| Posted: Wed Sep 03, 2008 4:01 pm Post subject: Re: passing a parameter to a function |  |
JRough wrote:
| Quote: | On Sep 2, 8:13 pm, FutureShock <futuresh...@att.net> wrote:
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. jstucklex@attglobal.net ================== |
| |
| | | JRough |  |
| Posted: Wed Sep 03, 2008 4:27 pm Post subject: Re: passing a parameter to a function |  |
| |  | |
On Sep 2, 8:13 pm, FutureShock <futuresh...@att.net> wrote:
| Quote: | JRough wrote: On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: 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
|
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_by)); $lease_row = true; break; case 'customer': $headers = GetHeaders($file_name); $result = SELECT_idle_days_customer($days,CLM_order_by($order_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"; |
| |
| | | FutureShock |  |
| Posted: Wed Sep 03, 2008 6:31 pm Post subject: Re: passing a parameter to a function |  |
| |  | |
| Quote: | 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_by)); $lease_row = true; break; case 'customer': $headers = GetHeaders($file_name); $result = SELECT_idle_days_customer($days,CLM_order_by($order_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 |
| |
| | | Curtis |  |
| Posted: Thu Sep 04, 2008 7:51 am Post subject: Re: passing a parameter to a function |  |
| |  | |
JRough wrote:
| Quote: | On Sep 2, 8:13 pm, FutureShock <futuresh...@att.net> wrote: JRough wrote: On Sep 2, 3:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: 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 |
| |
| | | FutureShock |  |
| Posted: Thu Sep 04, 2008 11:13 am Post subject: Re: passing a parameter to a function |  |
Curtis wrote: <snip>
| Quote: | 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 |
| |
|
|