Page 1 of 1

Using javascript in php

Posted: Tue Feb 01, 2005 3:22 pm
by thedro
I'm working on a dynamic system that exports a set of images with thumbnails, and the ability to click on the thumbnails and show them in the larger image viewer. The problem I'm having is I cannot get the images to switch to the larger viewer, because of the limitations of javascript and php compatibility. Is it possible to call a javascript function from php? If not, what do you recommend for calling a function from a dynamic php system. I will post code below.

Code: Select all

<?

// Connecting, selecting database
$link = mysql_connect('localhost', 'autox_autoxdbcon', 'audi')
   or die('Could not connect: ' . mysql_error());
mysql_select_db('autox_autox') or die('Could not select database'); 
$query = "SELECT * FROM `forsale` GROUP BY `year` ORDER BY `year`";
$result = mysql_query($query) or die(mysql_error());
while ($values = mysql_fetch_array($result))
&#123;
$descformat = nl2br($values&#1111;desc]);
	echo "<table width='700' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td><b><font size='+1'>$values&#1111;year] $values&#1111;model]</font></b></td>
  </tr>
</table>

<table width='700' height='246' border='0' cellpadding='0' cellspacing='0'>
  <tr>
    <td width='200'><b><font color='red' size='+1'>Price: $values&#1111;price]</font></b></td>
    <td width='226'>Vin: $values&#1111;vin]</td>
    <td width='274'>&nbsp;</td>
  </tr>
  <tr>
    <td height='227'><img src='images/forsale/$values&#1111;image]' width='267' height='200' id='main' name='main'></td>
    <td align='center' valign='top'><table width='100' height='188' border='1' cellpadding='2' cellspacing='0' bordercolor='#333333'>
      <tr>
        <td width='125' align='right'>";
		echo "<a href=# onClick=forsalecntrl('$values&#1111;img1]')><img src='images/forsale/thumbs/$values&#1111;img1]' width='50' height='50'></a>";
		echo "</td>
        <td width='125' align='right'><img src='images/forsale/thumbs/$values&#1111;img2]' width='50' height='50'></td>
      </tr>
      <tr>
        <td height='46' align='right'><a href='#' onClick='imgcntrl('images/forsale/$values&#1111;img3]', '1');'>
          <img src='images/forsale/thumbs/$values&#1111;img3]' width='50' height='50'></a></td>
        <td align='right'><a href='#' onClick='imgcntrl('images/forsale/$values&#1111;img4]', '1');'>
          <img src='images/forsale/thumbs/$values&#1111;img4]' width='50' height='50'></a></td>
      </tr>
      <tr>
        <td align='right'><a href='#' onClick='imgcntrl('images/forsale/$values&#1111;img5]', '1');'><img src='images/forsale/thumbs/$values&#1111;img5]' width='50' height='50'></a></td>
        <td align='right'><a href='#' onClick='imgcntrl('images/forsale/$values&#1111;img6]', '1');'><img src='images/forsale/thumbs/$values&#1111;img6]' width='50' height='50'></a></td>
      </tr>
    </table>
    <br></td>
    <td><div align='center' valign='top'>Description:<br>$descformat</div></td>
  </tr>
</table><hr width='700' noshade class='intro'>
Can you please let me know what you recommend or what options I have.


Thanks,

TheDro

Posted: Tue Feb 01, 2005 3:32 pm
by magicrobotmonkey
what is the imgcntrl function?

Posted: Tue Feb 01, 2005 3:37 pm
by thedro

Code: Select all

function forsalecntrl(il) &#123; //custom function
document.images&#1111;'main'].src=il;
main is the name of the image that is being switched, and il is the var that is passed through the javascript function. If you look at the functions they differ, forsalecntrl is the same as imgcntrl, just re-written as a custom function. When the code is working, I will be using the forsalecntrl for all the image switching.

Posted: Tue Feb 01, 2005 3:39 pm
by thedro
focus more on this section of code, this is how I would like the final product to be set up.

Code: Select all

echo "<a href=# onClick=forsalecntrl('$values&#1111;img1]')><img src='images/forsale/thumbs/$values&#1111;img1]' width='50' height='50'></a>";

Posted: Tue Feb 01, 2005 6:28 pm
by feyd
I've posted code that handles such things inside the client-side forum... where this thread is being moved, as this has almost nothing to do with php.