Jump to content


Problem with javascript in PHP Photoalbum

  • Please log in to reply
2 replies to this topic

#1 Jonas_R

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 September 2006 - 04:20 PM


Iam a bit unsure where to put this topic, if it wrong i hope the admin's will move it.

My problem is that i want to use a javascript inside a php code, and i cant seem to get it to work. Well it looks like this:

Iam pretty sure my problem is, that i cant seem to make the correct use of " " and ' ' .

<script language="JavaScript" src="mitjs.js"></script>  //here is a function called "na_open_window"


$query = mysql_query("SELECT id,path,parent_album FROM plogger_pictures
WHERE parent_album = 3 ORDER BY id") or die(mysql_error());
if (mysql_num_rows($query) == 0) {
 echo 'No pictures!<br>';
} else {
 echo '<table width="800" border="0"><tr>';
 echo'<td width="800">';
 while($row = mysql_fetch_assoc($query)) {
  $file =$row[id]."-".basename($row[path]);
  $name = "Anne".$row[id];
    //echo "<p>$file<p>";
  echo "<a href='javascript:na_open_window('$name',
'ploggerb2.1/images/$row[path]', 0, 0, 0, 0, 0, 0, 0, 0, 0)'
target='_self'><img src='ploggerb2.1/thumbs/$file' border='0'></a>";
  echo "&nbsp";


Best Regards

Jonas Rohde

#2 yonta

  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 23 September 2006 - 08:54 PM

It would help if you tell what it does output as it stands. But here are some suggestions.

Normaly when getting values from a mysql query i do this

$file =$row['id']."-".basename($row['path']); - notice the '' around column names. i'm not sure if they are mandatory but that's the commom way.

Then here i would o this:

echo '<a href="javascript:na_open_window(\''.$name.'\',
"ploggerb2.1/images/'.$row['path'].'", 0, 0, 0, 0, 0, 0, 0, 0, 0)"
target="_self"><img src="ploggerb2.1/thumbs/'.$file.'" border="0"></a>';

Using ' instead of " is quicker because php doesn't execute strings inside single quotes - this also means that when you want to print a variable you have to break the string and use the concatenation operator (.). Also when you want to escape quotes (be it single or double) use the backslash \ (notice the \ before the single quotes in $name variable).

See more at http://www.php.net/m...ypes.string.php on handling strings.

Hope this helps  :)

do it, do it right, do it right now

#3 Jonas_R

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 September 2006 - 09:44 PM


Thanks for the help :)
It was, what i was looking for.
Now everything works as it is supposed to.

Thx very much.

/Jonas R.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users