0

I have problem to calling function in string concatenation

i have this function :

function  site_url() {
    include("../connect.php");
    $title= mysql_query("select * from shop_option where shop_key='site_url' ");
    $row_title= mysql_fetch_array($title);
    print ''.$row_title['shop_feild'].'';
}

This function will tell website url eg ( http://google.com )

and i want to call this function in string concatenation

echo '<script language="javascript">'.'window.location =
    "'.site_url().'";'.'</script>';

i also called function into variable ! to testing but it's not work

$page = site_url();
echo '<script language="javascript">'.'window.location = "'.$page.'";'.'</script>';

so how can i call function when i want to string concatenation ?

2
  • "but it's not work" the error_log or inline error should give you a pretty good idea on what's wrong with your code Commented Feb 13, 2014 at 12:29
  • is that $row_title['shop_feild'] or shouldn't that be $row_title['shop_field'] Commented Feb 13, 2014 at 12:29

4 Answers 4

3

You need to return the result of site_url rather than printing the text immediately.

function  site_url() {
    include("../connect.php");
    $title= mysql_query("select * from shop_option where shop_key='site_url' ");
    $row_title= mysql_fetch_array($title);
    return $row_title['shop_feild'];
}
Sign up to request clarification or add additional context in comments.

Comments

1

your function should not print but return the value:

function  site_url() {
    include("../connect.php");
    $title= mysql_query("select * from shop_option where shop_key='site_url' ");
    $row_title= mysql_fetch_array($title);
    return''.$row_title['shop_field'].'';
}

in order to pass it to the caller which then prints the returned value.

1 Comment

Those empty string concatenations are unnecessary.
0

Instead of print, use return:

function  site_url() {
    include("../connect.php");
    $title= mysql_query("select * from shop_option where shop_key='site_url' ");
    $row_title= mysql_fetch_array($title);
    return $row_title['shop_field'];
}

Comments

0

Your function site_url() does not return the selected value.

function  site_url() {
  include("../connect.php");
  $title= mysql_query("select * from shop_option where shop_key='site_url'");
  $row_title = mysql_fetch_array($title);
  return $row_title['shop_feild'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.