Bluehost.com Web Hosting $6.95

function returns no value

This is a discussion on function returns no value within the PHP General forums, part of the PHP Programming Forums category; Hello, with the following call I try to print a string out of DB echo $allg->translate($db, $lang, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008
Ali Reza Sajedi
 
Posts: n/a
Default function returns no value

Hello,

with the following call I try to print a string out of DB

echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);

function translate () should do a DB querry and returns the requested
string. Although the querry yields a positive result, the function returns
no value.

Here is the function:

function translate ($db, $lang, $MaiKey, $page, $pid) {

$statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
page='$page' AND pid='$pid'";

$result = $db->Execute($statement);

if ($result=== false) die();

return $result->fields[0];
}

Could anybody see what is going wrong here?

I appreciate any hint.

Ali

Reply With Quote
  #2 (permalink)  
Old 04-21-2008
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] function returns no value

On Sun, Apr 20, 2008 at 4:51 PM, Ali Reza Sajedi <arsajedi@khanehjou.com>
wrote:

> Hello,
>
> with the following call I try to print a string out of DB
>
> echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);
>
> function translate () should do a DB querry and returns the requested
> string. Although the querry yields a positive result, the function returns
> no value.
>
> Here is the function:
>
> function translate ($db, $lang, $MaiKey, $page, $pid) {
>
> $statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
> page='$page' AND pid='$pid'";
>
> $result = $db->Execute($statement);
>
> if ($result=== false) die();
>
> return $result->fields[0];
> }
>
> Could anybody see what is going wrong here?



its hard to say, since we cant see whats going on inside the Execute
function... you might try to add a
var_dump($result);
directly after the call to Execute, just for debugging purposes, then remove
it once you know whats going on.

-nathan

Reply With Quote
  #3 (permalink)  
Old 04-21-2008
Liran Oz
 
Posts: n/a
Default Re: [PHP] function returns no value

Can't really know without the rest of the code.
Check if the function really returns and not Dying (Add some messege like:
die("help me I'm dying"); ).
Also use print_r or something like to see what's inside the fields array.
it is possible that it's an associative array and you are using the wrong
index (0)

Liran
----- Original Message -----
From: "Ali Reza Sajedi" <arsajedi@khanehjou.com>
To: <php-general@lists.php.net>
Sent: Sunday, April 20, 2008 11:51 PM
Subject: [php] function returns no value


> Hello,
>
> with the following call I try to print a string out of DB
>
> echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);
>
> function translate () should do a DB querry and returns the requested
> string. Although the querry yields a positive result, the function returns
> no value.
>
> Here is the function:
>
> function translate ($db, $lang, $MaiKey, $page, $pid) {
>
> $statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
> page='$page' AND pid='$pid'";
>
> $result = $db->Execute($statement);
>
> if ($result=== false) die();
>
> return $result->fields[0];
> }
>
> Could anybody see what is going wrong here?
>
> I appreciate any hint.
>
> Ali
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Reply With Quote
  #4 (permalink)  
Old 04-21-2008
Ali Reza Sajedi
 
Posts: n/a
Default Re: [PHP] function returns no value

I added var_dump($result); to the function.

As part of the output I get the following:

["fields"]=> array(1) { ["fa"]=> string(22) "ورود به سایت"}

which is the string which should be returned and printed.

The result is there, however, it couldn't be printed.

Any ideas?

Regards

Ali

----- Original Message -----
From: Nathan Nobbe
To: Ali Reza Sajedi
Cc: php-general@lists.php.net
Sent: Monday, April 21, 2008 12:42 AM
Subject: Re: [php] function returns no value


On Sun, Apr 20, 2008 at 4:51 PM, Ali Reza Sajedi <arsajedi@khanehjou.com>
wrote:

Hello,

with the following call I try to print a string out of DB

echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);

function translate () should do a DB querry and returns the requested
string. Although the querry yields a positive result, the function returns
no value.

Here is the function:

function translate ($db, $lang, $MaiKey, $page, $pid) {

$statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
page='$page' AND pid='$pid'";

$result = $db->Execute($statement);

if ($result=== false) die();

return $result->fields[0];
}

Could anybody see what is going wrong here?

its hard to say, since we cant see whats going on inside the Execute
function... you might try to add a
var_dump($result);
directly after the call to Execute, just for debugging purposes, then remove
it once you know whats going on.

-nathan

Reply With Quote
  #5 (permalink)  
Old 04-21-2008
Thijs Lensselink
 
Posts: n/a
Default Re: [PHP] function returns no value

Quoting Ali Reza Sajedi <arsajedi@khanehjou.com>:

> I added var_dump($result); to the function.
>
> As part of the output I get the following:
>
> ["fields"]=> array(1) { ["fa"]=> string(22) "ورود به سایت"}
>
> which is the string which should be returned and printed.
>
> The result is there, however, it couldn't be printed.
>
> Any ideas?
>
> Regards
>
> Ali
>
> ----- Original Message ----- From: Nathan Nobbe
> To: Ali Reza Sajedi
> Cc: php-general@lists.php.net
> Sent: Monday, April 21, 2008 12:42 AM
> Subject: Re: [php] function returns no value
>
>
> On Sun, Apr 20, 2008 at 4:51 PM, Ali Reza Sajedi
> <arsajedi@khanehjou.com> wrote:
>
> Hello,
>
> with the following call I try to print a string out of DB
>
> echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);
>
> function translate () should do a DB querry and returns the requested
> string. Although the querry yields a positive result, the function
> returns no value.
>
> Here is the function:
>
> function translate ($db, $lang, $MaiKey, $page, $pid) {
>
> $statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
> page='$page' AND pid='$pid'";
>
> $result = $db->Execute($statement);
>
> if ($result=== false) die();
>
> return $result->fields[0];


Try $result->fields["fa"] instead.

> }
>
> Could anybody see what is going wrong here?
>
> its hard to say, since we cant see whats going on inside the Execute
> function... you might try to add a
> var_dump($result);
> directly after the call to Execute, just for debugging purposes, then
> remove it once you know whats going on.
>
> -nathan -- PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



Reply With Quote
  #6 (permalink)  
Old 04-21-2008
Ali Reza Sajedi
 
Posts: n/a
Default Re: [PHP] function returns no value

using $result->fields["fa"] did solve the problem.

thanks very much Thijs

----- Original Message -----
From: "Thijs Lensselink" <dev@lenss.nl>
To: <php-general@lists.php.net>
Sent: Monday, April 21, 2008 2:48 PM
Subject: Re: [php] function returns no value


Quoting Ali Reza Sajedi <arsajedi@khanehjou.com>:

> I added var_dump($result); to the function.
>
> As part of the output I get the following:
>
> ["fields"]=> array(1) { ["fa"]=> string(22) "ورود به سایت"}
>
> which is the string which should be returned and printed.
>
> The result is there, however, it couldn't be printed.
>
> Any ideas?
>
> Regards
>
> Ali
>
> ----- Original Message ----- From: Nathan Nobbe
> To: Ali Reza Sajedi
> Cc: php-general@lists.php.net
> Sent: Monday, April 21, 2008 12:42 AM
> Subject: Re: [php] function returns no value
>
>
> On Sun, Apr 20, 2008 at 4:51 PM, Ali Reza Sajedi
> <arsajedi@khanehjou.com> wrote:
>
> Hello,
>
> with the following call I try to print a string out of DB
>
> echo $allg->translate($db, $lang, 14, "auth/authCallback", 4);
>
> function translate () should do a DB querry and returns the requested
> string. Although the querry yields a positive result, the function
> returns no value.
>
> Here is the function:
>
> function translate ($db, $lang, $MaiKey, $page, $pid) {
>
> $statement = "SELECT fa FROM language WHERE MaiKey='$MaiKey' AND
> page='$page' AND pid='$pid'";
>
> $result = $db->Execute($statement);
>
> if ($result=== false) die();
>
> return $result->fields[0];


Try $result->fields["fa"] instead.

> }
>
> Could anybody see what is going wrong here?
>
> its hard to say, since we cant see whats going on inside the Execute
> function... you might try to add a
> var_dump($result);
> directly after the call to Execute, just for debugging purposes, then
> remove it once you know whats going on.
>
> -nathan -- PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:25 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0