[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:
<?
$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']?> & <?=$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:
<?
$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))) {
// ****** 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']?> & <?=$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
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;
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.