0

I have a php variable ($num_rows) that i want to add to button value.

I am not getting value i want which should show like "Pending Friend Requests(0)"

I tried many different things but is not working. How can i write the code so that i get right value?

Here is the code:

$interactionBox= '<input type="button" value="Pending Friend Requests(\'.$num_rows.\')" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');"/>'; 

I tried:

value="Pending Friend Requests(".$num_rows.")"
value="Pending Friend Requests(.".$num_rows.".)"

3 Answers 3

2

You need to remove the backslashes before the single quotes for the variable to be included like so:

$interactionBox= '<input type="button" value="Pending Friend Requests('.$num_rows.')" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');"/>'; 
Sign up to request clarification or add additional context in comments.

Comments

1

There's something wrong with your escaped ' around the values.

Do it this way: $variable = "parsed string, so the variable name can be inside the string $num_rows"; $variable = 'This is a static string so the variables have to be appended, e.g. ' . $num_rows . ', to work.';

Escaped quote characters (\" or \') are treted as if they'd be any other standard character inside the string.

Comments

0

just try this one value="Pending Friend Requests('.$num_rows.')" no need to escape single quotes within double quotes

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.