Page 1 of 1

PHP and Javascript problem

Posted: Sat Nov 24, 2007 11:57 am
by mayo23
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to create a table of thumbnails that will open a new window when any of the thumbs are clicked (to show the full size image).  

The first stage of the code was successful, and the query created a table which showed all the images in the database.

Code: Select all

<td width="584">

<?php

# execute SQL statement 
$image_query = tep_db_query("select * from " . TABLE_GAMEIMAGES . " where products_id=28");

echo "<table width=100%>"; 
$ct=1; 
while($row = tep_db_fetch_array($image_query)) 
{ 
    if($ct==1) echo "<tr>"; 
    echo "<td width=25%><img src=thumbs/{$row['image_file']}></td>"; 
    if($ct==4){ echo "</tr>"; $ct=0; }//Change comparison number to adjust columns per row 
    $ct++; 
} 
echo "</table>"; 
?>

</td>
There were 8 images in the database and the resulting table showed two rows of 4 thumbnail images.

However, when I introduced the javascript into the php code, only 7 of the images appeared. The first image in the query didn't appear, and the first column in the first row is blank.

Here's the code

Code: Select all

<td width="584">

<?php

# execute SQL statement 
$image_query = tep_db_query("select * from " . TABLE_GAMEIMAGES . " where products_id=28");
echo "<table width=100%>"; 
$ct=1; 
while($row = tep_db_fetch_array($image_query)) 
{ 
    if($ct==1) echo "<tr>"; 
	echo '<td><script language="javascript">document.write(\'<a href="javascript:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE2, 'product_id=' . $product_info['products_id']) . '&image_id=' . $row['image_id'] . '\\\')"><img src="thumbs/' . $row['image_file'] . '" hspace="5" vspace="5"</a>\');</script></td>';
    if($ct==4){ echo "</tr>"; $ct=0; }//Change comparison number to adjust columns per row 
    $ct++; 
} 
echo "</table>"; 
?>

</td>

When I view the source of the outputed HTML file, and replace the PHP coding with the actual HTML code generated, the first image appears in place.

Starting to completely do my head in!!!!


Any Ideas anyone?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]