[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

place variable inside script

Posted on 2011-09-22
14
Medium Priority
?
424 Views
Last Modified: 2012-05-12
I have the following php script.  I want to place the poll daddy id inside the script but not sure how to do that.  for example, the variable is listed as: $poll = bwp_get_poll('123457890');

using <?php echo $poll->id; ?> how do I replace the id in this path http://static.polldaddy.com/p/123457890.js using opening and close php tags

Any ideas?
<?php $gender = (get_user_field ("gender", $user->ID));
	
if ( $gender == "1" ) {
$poll = bwp_get_poll('123457890');

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/123457890.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/123457890/\">Do you believe in love at first sight?</a></noscript>";

} else {
$poll = bwp_get_poll('123457891');

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/123457890.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/123457891/\">Do you believe in love at first sight?</a></noscript>";
}?>If you would like to submit a survey question for our members to answer, email us at <a title="email info@domain.com" href="http://mailto:info@domain.com">info@domain.com</a>.

Open in new window

0
Comment
Question by:COwebmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36583544
Did you try this:
echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/123457890.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/poll->id/\">Do you believe in love at first sight?</a></noscript>";
0
 
LVL 6

Expert Comment

by:bartvd
ID: 36583549
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36583555
Looking at this...

$poll = bwp_get_poll('123457890');

And the other usages in the question it looks like bwp_get_poll returns an object.  Is that true?  If so, please use var_dump() to print out the returned object.  Use echo "<pre>"; before the dump so it is readable.  Post the output from var_dump() here.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:COwebmaster
ID: 36583626
@bartvd, that solution didn't work

@Ray_Paseur, yes, I just want to return the result of that variable inside that url path but not sure where I need to add ?> and <?php in that section of the code.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36584032
Please read my request at ID:36583555.  I would like to help you get this right.  I need to see what the object contains.
0
 

Author Comment

by:COwebmaster
ID: 36584121
sorry, I'm not understanding.  I placed this line of code there but the whole page broke.

echo"var_dump()"
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36584640
Should be

echo var_dump();
0
 

Author Comment

by:COwebmaster
ID: 36587311
Okay, I tried that but it's not working.  What am I doing wrong?
<?php $gender = (get_user_field ("gender", $user->ID));
	
if ( $gender == "1" ) {
$poll = bwp_get_poll('123457890');

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/123457890.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/123457890/\">Do you believe in love at first sight?</a></noscript>";

} else {
$poll = bwp_get_poll('123457891');

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/123457890.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/123457891/\">Do you believe in love at first sight?</a></noscript>";
}

echo var_dump();

?>If you would like to submit a survey question for our members to answer, email us at <a title="email info@domain.com" href="http://mailto:info@domain.com">info@domain.com</a>.

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36587461
Change line 16 to this:

echo "<pre>";
var_dump($poll);

You can learn how any PHP function works by looking it up on the PHP web site.  Check the link here:
http://php.net/manual/en/function.var-dump.php
0
 

Author Comment

by:COwebmaster
ID: 36587491
okay, cool that worked :)  This is the output:
object(stdClass)#203 (7) {

  ["folderID"]=>

  string(8) "15589466"

  ["content"]=>

  string(44) "Do you believe in love at first sight? (Men)"

  ["id"]=>

  string(7) "5515751"

  ["created"]=>

  string(19) "2011-09-19 15:35:25"

  ["responses"]=>

  int(0)

  ["owner"]=>

  int(1)

  ["closed"]=>

  int(0)

}

If you would like to submit a survey question for our members to answer, email us at info@domain.com.

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 36587690
Here is the object, tidied up a little bit so we can read it more easily.
["folderID"]  => "15589466"
["content"]   => "Do you believe in love at first sight? (Men)"
["id"]        => "5515751"
["created"]   => "2011-09-19 15:35:25"
["responses"] => 0
["owner"]     => 1
["closed"]    => 0

Open in new window

Here is how I would probably go about using the object.  Follow the variable $id in the script below.  I am not sure whether you want that variable in the JS link or not.
if ( $gender == "1" ) {
$poll = bwp_get_poll('123457890');
$id   = $poll->id;

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/$id.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/$id/\">Do you believe in love at first sight?</a></noscript>";

} else {
$poll = bwp_get_poll('123457891');
$id   = $poll->id;

echo"<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/$id.js\"></script>
<noscript><a href=\"http://polldaddy.com/poll/$id/\">Do you believe in love at first sight?</a></noscript>";
}?>If you would like to submit a survey question ...

Open in new window

0
 

Author Comment

by:COwebmaster
ID: 36587828
okay, do I need to also include the following in the page?

["folderID"]  => "15589466"
["content"]   => "Do you believe in love at first sight? (Men)"
["id"]        => "5515751"
["created"]   => "2011-09-19 15:35:25"
["responses"] => 0
["owner"]     => 1
["closed"]    => 0
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36587922
No, that's just information that I needed to see what the contents of the object looked like.  I might have been able to guess, but it was easier and more reliable to see it printed out with var_dump.

Do you understand what we are doing with the $id variable?
0
 

Author Comment

by:COwebmaster
ID: 36587950
yes, thanks Ray_Paseur!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question