Jump to content

Java Inside PHP Help


Sleeper

Recommended Posts

I want to use a window.open java script but generate the list of links via phpe

 

<script>
function multiWin()
{
$s=2;
while ($s <= 25) {
echo '$links[$s]';
$s++;
}
}
</script>

 

I realize the above coding is wrong and it will be inside php so how would I do it correctly? Also I want it to drop a liner after every link. I've played around with this for a few hours now and I am completely lost now.

Link to comment
Share on other sites

Sleeper,

 

It sounds like you could store PHP in an include file and then write your JavaScript in PHP.

 

Example (index.php):

<?php
include('js.php');
?>

 

js.php:

<?php
echo "<script>
function multiWin()
{";

$s=2;
while ($s <= 25) {
echo '$links[$s]';
$s++;
}

echo "}
</script>";
?>

Link to comment
Share on other sites

$data = mysql_query("SELECT * FROM $GT $sort LIMIT $L") or die(mysql_error());

while ($info = mysql_fetch_array($data)){
$links[] = 'window.open("'.$info[link].'");';
}

echo '
<script type="text/javascript">
function multiWin()
'.$fill[1].'
</script>';

 

This is what I thought would work and it dose pull in the one item, however I cant get the loop so that it can pull in all over them.

Link to comment
Share on other sites

ok So...

 

$data = mysql_query("SELECT * FROM $GT $sort LIMIT $L") or die(mysql_error());

while ($info = mysql_fetch_array($data)){
$links[] = 'window.open("'.$info[link].'");';
}
echo '
<script type="text/javascript">
function multiWin()';
echo $links[0];
echo '</script>';

 

That works to get the first link of the array up there. However if I try to do something like...

 

$data = mysql_query("SELECT * FROM $GT $sort LIMIT $L") or die(mysql_error());

while ($info = mysql_fetch_array($data)){
$links[] = 'window.open("'.$info[link].'");';
}
echo '
<script type="text/javascript">
function multiWin()';
$s=1;
while ($s <= 25) {
echo $links[$s];
$s++;
}
echo '</script>';

 

It tries to open up all the pages on page load instead of waiting for the person to click on the link.

Link to comment
Share on other sites

$data = mysql_query("SELECT * FROM $GT $sort LIMIT $L") or die(mysql_error());

while ($info = mysql_fetch_array($data)){
$links[] = 'window.open("'.$info[link].'");';
}
echo '
<script type="text/javascript">
function multiWin()';
for ($s = 0; $s <= 25; $s++)
{
echo $links[$s];
}
echo '</script>';

 

This dose the same thing. Trys to open up all the windows on page load and when you click on the link that should open them up it just opens one. Maybe im going about this the wrong way.

 

What im doing is I have a page of 25 links that will be generated from the data base and they will all be listed, but I want to have for the user a one click option where it will open all the links in new tabs and keep the original page open. Maybe you guys know of a better way to do this?

Link to comment
Share on other sites

<script type="text/javascript">
function multiWin()window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=838475293&from_name=Jody&time=1257493423&gift_sig=ea96ed74239599890dfc28dfe449bc2c&cid=send_gift&ruid=838475293");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=605937723&from_name%3C%3Bred%3E%3BPh%E2%99%A5+%E2%99%A5+%E2%99%A5&time=1256099925&gift_sig=8297fe13cd8a1e74ee76fc90e16506ed&cid=send_gift&ruid=605937723");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=511784816&from_name%3C%3Bb%3E%3B%3C%3Bred%3E%3BKC&time=1257627443&gift_sig=dc6cdca41ffd38f7e88771b9adb02e79&cid=send_gift&ruid=511784816");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1631086900&from_name=Jana&time=1257659665&gift_sig=8c8e5e49f4b241a09d00b53d6adf3a26&cid=send_gift&ruid=1631086900");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=769927701&from_name=Sharp&time=1257814477&gift_sig=74d75dda932ac9f043a0d0341f0c1e02&cid=send_gift&ruid=769927701");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1314540015&from_name%3C%3Bb%3E%3B%3C%3Bred%3E%3B%E2%99%A5JoJo%E2%99%A5&time=1257917109&gift_sig=5ac60c6263df7c15ddfbcc54c94c5022&cid=send_gift&ruid=1314540015");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=718720787&from_name=TJ&time=1258086324&gift_sig=659a07f4eac7e94cb9ed58214cb21a7e&cid=send_gift&ruid=718720787");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=608277492&from_name%3C%3Bred%3E%3BTJ%3C%3Bb%3E%3B%3C%3Bi&time=1258350982&gift_sig=5a6cd9d7a18dc200074feeb0df138897&cid=send_gift&ruid=608277492");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1543272670&from_name=Farmer+Mike&time=1258387748&gift_sig=0987d5834b99160db10947083dd3f4dc&cid=send_gift&ruid=1543272670");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1550840274&from_name=Snicklfritz&time=1258481902&gift_sig=937770252fae495eb47f9c8e65211e9e&cid=send_gift&ruid=1550840274");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1258795029&gift_sig=8f6c35dfac189b7a62b864401afc68f4&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1724686972&from_name=niamh+b&time=1258707295&gift_sig=66785250a2b7c7b501aede812144c0be&cid=send_gift&ruid=1724686972");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1481950490&from_name=Prezzies%20Acres&time=1258738597&gift_sig=6c5f61e5eb6273e98a669f9442b87906&cid=send_gift&ruid=1481950490");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1258795029&gift_sig=8f6c35dfac189b7a62b864401afc68f4&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1258952925&gift_sig=768efd96dc5a0abe1e7cefdf931ad293&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1259032762&gift_sig=cbc9f3417076b22346126686e2baad59&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1259298198&gift_sig=072de12fdacbb5e992e6fa20fb07e565&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1259417898&gift_sig=3593b52082d68d2cd1fa643b3a4bc9e7&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1550840274&from_name=Snicklfritz&time=1259428942&gift_sig=b34e19d5ee91fe2aee1bd1c364fe4c90&cid=send_gift&ruid=1550840274");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1544674832&from_name=Sassy+Gal&time=1259591556&gift_sig=2e985e775b035d6a517150bdeabc584d&cid=send_gift&ruid=1544674832");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1259649598&gift_sig=f1d45acc3019289124b44255b201d687&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=722138484&from_name=Cipto&time=1259888834&gift_sig=f61c053a99bbf7202e28f6583cd65f45&cid=send_gift&ruid=722138484");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1604956096&from_name=Jessi&time=1259957063&gift_sig=73d47178a34da3d002521df903612631&cid=send_gift&ruid=1604956096");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1490731322&from_name=MommyKathy&time=1260336514&gift_sig=6f8fdd42a49cbbf113e572377394d869&cid=send_gift&ruid=1490731322");window.open("http://apps.facebook.com/farmtown/play/?type=FF&from_uid=1206351194&from_name=Kathy&time=1260750427&gift_sig=f6a95d38e2bb3a4df05f4c6aa088a40d&cid=send_gift&ruid=1206351194");</script><tr><td align="left" colspan="3" style="padding: 5px 0px 5px 0px;"><font class="pagesnum">Open All 25 At Once. 
<a href="JavaScript:multiWin();">Click Here</a>

Link to comment
Share on other sites

Recommendations below.  The main problem you were having is that your javascript function was not encapsulated with { }.  Case solved?

$data = mysql_query("SELECT * FROM $GT $sort LIMIT $L") or die(mysql_error());

while ($info = mysql_fetch_array($data)){
$links[] = 'window.open("'.$info[link].'");\r\n';  //\r\n will make the source a LOT more readable... easier to find errors.
}

echo '
<script type="text/javascript">
function multiWin(){\r\n';

for ($s = 0; $s <= count($links); $s++)
{
echo $links[$s];
}
echo '}</script>';

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.