Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Getting php vars to work in inline javascript problem


[SOLVED] Getting php vars to work in inline javascript problem

Reply
  #1 (permalink)  
Old 11-06-08, 05:39 AM
med267 med267 is offline
New Member
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Getting php vars to work in inline javascript problem

I have a problem getting my php variables to interpolate correctly when part of my anchor tags inline javascript for onmouseover or onmouseout.

I have the whole statement working when outside of my php if statement, but when I try to get it working within the if statement I have trouble escaping the statement properly.

If someone has some insight to this problem it would be very helpful *

Here is the code that works outside the if statement:

PHP Code:

   <!-- / END BLOCK -->

    <?
}

foreach (
$dates as $date)
{
    
$label strtotime($date);
    
$label date("F jS Y"$label);
?>
    <div class="block"> 
        <h2><?=$label?></h2>
      <p>

    <?
    $d 
sqlq("SELECT * FROM `weddings` WHERE `event_date`='".$date."' ORDER by `rating` ASC");
    while (
$record mysql_fetch_assoc($d))    
    {
        if (
strpos($record['url'], 'http://') === FALSE$record['url'] = 'http://'.$record['url'];
    
// Check Date & reformat link to end in file type .mp4 inplace of .wmv if current date is past 2008-11-02
    
    
$newmp4formatStartDate '2008-11-02';

    if (
date('Ymd') > date('Ymd'strtotime($newmp4formatStartDate))) $mp4rec $record['url'];
    
    
?>
// THIS IS THE CODE I AM FOCUSING ON *****
<a href="<?=str_replace("wmv""mp4"$mp4rec)?>" onMouseOver="javascript:spopup(this,<?=$record['id']?>)" onMouseOut="javascript:hpopup()"> <?=$record['fn_male']?> &amp; <?=$record['fn_female']?>'s <?=$record['event_title']?> >></a>
<br>
// END    
    <?
    
}
    
?>

    </p>
    </div>
<?
}
?>
    <!-- / END BLOCK -->
OKAY & here is the version not working inside an if statement:
PHP Code:

    <?

}

foreach (
$dates as $date)
{
    
$label strtotime($date);
    
$label date("F jS Y"$label);
    
$label2 strtotime($date);
    
$label2 date('Ymd'$label2);
?>
    <div class="block"> 
        <h2><?=$label?></h2>
      <p>

    <?
    $d 
sqlq("SELECT * FROM `weddings` WHERE `event_date`='".$date."' ORDER by `rating` ASC");
    while (
$record mysql_fetch_assoc($d))    
    {
        if (
strpos($record['url'], 'http://') === FALSE$record['url'] = 'http://'.$record['url'];
        
    
// ****** Check Date & reformat link to end in file type .mp4 instead of .wmv if current date is newer then 2008-11-02
    
    
$newmp4formatStartDate '2008-11-02';

        if (
$label2 date('Ymd'strtotime($newmp4formatStartDate))) {
    
             
$mp4rec $record['url'];
             
$mp4rec str_replace("wmv""mp4"$mp4rec);
    
    
    
// ****** The lines commented out beloware not escaped properly & doesnt work.... needs to be fixed, it works outside of if statement ****
/*    
    echo "<a href="<?=str_replace("wmv", "mp4", $mp4rec)?>" onMouseOver="javascript:spopup(this,<?=$record['id']?>)" onMouseOut="javascript:hpopup()"> <?=$record['fn_male']?> &amp; <?=$record['fn_female']?>'s <?=$record['event_title']?> >></a>
<br>";
*/

// HERE IS MY ATTEMPT TO FIX IT BELOW... IT WORKS UNTIL I TRY TO ADD 
// <?=$record['id']
?> AFTER THE COMMA IN SPOPUP THEN I GET
// Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING  showing up on the same line number

    $blink = "<a href=\"$mp4rec\" onMouseOver=\"javascript:spopup(this,<?=$record['id']?>);\" onMouseOut=\"javascript:hpopup()\">lolo</a>";
    $blink .= '<br>';
    echo $blink;

} else {



}

?>
Reply With Quote
  #2 (permalink)  
Old 11-06-08, 06:30 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You might want to change this:

Quote:
echo "<a href="<?=str_replace("wmv", "mp4", $mp4rec)?>" onMouseOver="javascript:spopup(this,<?=$record['id']?>)" onMouseOut="javascript:hpopup()"> <?=$record['fn_male']?> &amp; <?=$record['fn_female']?>'s <?=$record['event_title']?> >></a>
<br>";
To use the hereto or here syntax:

http://us2.php.net/manual/en/function.echo.php

PHP Code:

echo <<<END

This uses the "here document" syntax to output
multiple lines with 
$variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END; 
Like so:

PHP Code:

$mp4=str_replace("wmv""mp4"$mp4rec);

echo <<<END
<a href="$mp4" onMouseOver="javascript:spopup(this,{$record['id']})" onMouseOut="javascript:hpopup()"> {$record['fn_male']} &amp; {$record['fn_female']}'s {$record['event_title']}</a> 
<br />
END; 
* Not sure if {$record['fn_male']} notation will work - but you can adjust that.
Reply With Quote
  #3 (permalink)  
Old 11-06-08, 02:44 PM
med267 med267 is offline
New Member
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up wirehopper Thanks *

wirehopper,

That worked perfectly when the brackets were put around as you suggested.

I had tried heredoc style before with no easy result, but your suggestions helped & it does work.

I had searched for hours & days for more documentation when calling javascript functions with php mysql arguments & came up with very little that seemed relevant.

Thank you very much again & I hope I will be able to contribute in the same way.

med267
Reply With Quote
  #4 (permalink)  
Old 11-06-08, 06:20 PM
user1001 user1001 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
mark as solved please
Reply With Quote
  #5 (permalink)  
Old 11-06-08, 08:38 PM
med267 med267 is offline
New Member
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Solved

Quote:
Originally Posted by user1001 View Post
mark as solved please

Thanks for the reminder. I think I marked it correctly thru thread tools.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem with php include html website tyrowen HTML/XHTML/XML 1 06-20-08 03:27 AM
Urgent problem with PHP domxml_open_mem(), php extension php_domxml.dll. Need help! Oskare100 Web Servers 3 01-03-07 05:08 AM
[For Hire] Web Designer / Developer - PHP, ASP - 4+ years experience Czaries Job Offers & Assistance 0 12-22-05 11:20 AM
PHP Sessions problem dannyallen PHP 1 06-26-04 10:43 AM
Javascript vs PHP, problem with arrays Chuff JavaScript 0 10-03-03 04:01 AM


All times are GMT -5. The time now is 08:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.