Jump to content

Recommended Posts

I want to incorprate a javascript into my existing php.

The line in question display an image retrieved by refernece to a database.

I want the js to display a pop up  when the image is roled over.

I cant seem to write this without a parse error.

The existing code is

<?php
echo "<a href='show_book.php?product_id={$row['product_id']}'>
        	<img src= './images/{$row['pix']}' border='0'
              width='100' height='80'></a><br />";

The js code is


<a href="#" onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()">Info</a>	

 

My attempt is


<a href="onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"<?php('show_book.php?product_id={$row['product_id']}')?><img src= <?php'./images/{$row['pix']}'?> border='0' width='100' height='80'></a><br />";

Any advice is much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/
Share on other sites

Hi thanks for coming back

I think maybe you missed all of the code, the php part, as follows:-


<a href="onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"(<?php'show_book.php?product_id={$row['product_id']}')?><img src= <?php'./images/{$row['pix']}'?> border='0' width='100' height='80'></a><br />";

I have modified the script to this. Still parse error.

Can anybody help please.

<a href="<?php('show_book.php?product_id={$row['product_id']}')?>"onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"<?php('show_book.php?product_id={$row['product_id']}')?><img src= <?php'./images/{$row['pix']}'?> border="0" width="100" height="80"></a>

Ok I tried this. No good yet.

<?php
  echo'  <a href="('show_book.php?product_id={$row['product_id']}')?>"onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"<?php('show_book.php?product_id={$row['product_id']}')?><img src= <?php'./images/{$row['pix']}'?> border="0" width="100" height="80"></a>';
              

not that

 

<a href="<?php echo 'show_book.php?product_id={$row['product_id']}'; ?>"onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"<?php echo 'show_book.php?product_id={$row['product_id']}';?>><img src= "<?php echo './images/{$row['pix']}';>" border="0" width="100" height="80"></a>

Going off of Blade280891's code, I think you are missing a '?' for the ending "?>":

<a href="<?php echo 'show_book.php?product_id={$row['product_id']}'; ?>"onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"<?php echo 'show_book.php?product_id={$row['product_id']}';?>><img src= "<?php echo './images/{$row['pix']}';?>" border="0" width="100" height="80"></a>

Here is the full page in al its glory.

Thanks for your interest.

<?php
require ('book_sc_fns.php');
include_once('./includes/config.inc.php');
session_start();

do_html_header();


// get categories out of database
  $cat_array = get_categories();

  // display as links to cat pages
  display_categories($cat_array);
  
  
//get featured books

$connection = db_connect();
  $query = "select * From products WHERE Featured='1' Order by cat_id";
  $result = mysql_query($query);
  if (!$result)
  return false;
  $num_cats = mysql_num_rows($result);
  if ($num_cats ==0)
  return false;
  
echo '<td>';/* set cell for contents within overall table*/
echo'<div id="contents">';
echo'<table  width="600" border="0" cellpadding="50" cellspacing="5" >';
//echo"<caption>Welcome to e-Books4U electronic Book store</caption>";
echo'<thead><tr><td  colspan="5" ><h6>This Months Featured e-Books</h6></td></tr>
</thead>';
  $i=0;
  $size=3;
  echo "<tbody>";
    echo "<tr>";
  while ($row = mysql_fetch_array($result,MYSQL_ASSOC))   
  {
    /* display picture  */
    
    ?>
    <td class="p1">
    <td><a href="<?php echo'show_book.php?product_id={$row['product_id']}';?>>
        	<img src=<?php echo './images/{$row['pix']}';?> border='0'
              width='80' height='100'>onmouseover="ajax_showTooltip('demo-pages/js-calendar.html',this);return false" onmouseout="ajax_hideTooltip()"</a>"
    
  	<?php
/* display row for each featured book */
$url= 'show_book.php?product_id='.($row{'product_id'});
    $title = $row['title'];
    do_html_url($url,$title);
    echo "ONLY<br />";
    echo "£{$row['price']}</td>";
    $i++;
    
    if($i==$size)
{
  echo "</tr><tr>";
  
  $i=0;
}
    
}
  echo "<tr><td colspan='5'><h6>Latest Additions to the e-book catalog</h6></td></tr>";
  
  //get Latest Additions
  
  $connection = db_connect();
  $query = "select * From products WHERE New='1' Order by cat_id";
  $result = mysql_query($query);
  if (!$result)
  return false;
  $num_cats = mysql_num_rows($result);
  if ($num_cats ==0)
  return false;
  
  echo "<tr>";
  while ($row = mysql_fetch_array($result,MYSQL_ASSOC))   
  {
    /* display picture  */
    
    echo "<td><a href='show_book.php?product_id={$row['product_id']}'>
        	<img src= './images/{$row['pix']}' border='0'
              width='100' height='80'></a><br />";

/* display row for each featured book */
$url= 'show_book.php?product_id='.($row{'product_id'});
    $title = $row['title'];
    do_html_url($url,$title);
    echo "Special Price <br />";
    echo "£{$row['price']}</td>";
    $i++;
    
    if($i==$size)
{
  echo "</tr><tr>";
  
  $i=0;
}
    
}
	echo "<tr><td text-align='center' colspan='5'><h6>Bargin e-books that can get you started in business today</h6></td></tr>";  

	//get business ebooks
  
  $connection = db_connect();
  $query = "select * From products WHERE  business='1'  Order by cat_id";
  $result = mysql_query($query);
  if (!$result)
  return false;
  $num_cats = mysql_num_rows($result);
  if ($num_cats ==0)
  return false;
  
  echo "<tr>";
  while ($row = mysql_fetch_array($result,MYSQL_ASSOC))   
  {
    /* display picture  */
    
    echo "<td><a href='show_book.php?product_id={$row['product_id']}'>
        	<img src= './images/{$row['pix']}' border='0'
              width='100' height='80'></a><br />";
              
/* display row for each business book */
$url= 'show_book.php?product_id='.($row{'product_id'});
    $title = $row['title'];
    do_html_url($url,$title);
    echo "Special Price";
    echo "£{$row['price']}<br />";
    echo "<a href='./business/{$row['promo_link']}'>Read Review</a></td>\n";
    $i++;
    
    if($i==$size)
{
  echo "</tr><tr>";
  
  $i=0;
}
    
}
  
  echo "</tbody></table>\n";/* end contents table*/
  echo "</div>";/* end contents div */
  echo '</td>';/* end overall contents cell*/
  echo '</tr></table>';/* end overall table row and table*/
/* echo '</div>';/* end home div*/
  
do_html_footer();
exit;
?>

/* 
  
  // if logged in as admin, show add, delete, edit cat links
if(isset($_SESSION['admin_user']))
  {
    display_button('admin.php', 'admin-menu', 'Admin Menu');
  }*/



I think the problem is the single quotes with the array variable inside. Change these two lines to use double quotes like this:

    <td><a href="<?php echo "show_book.php?product_id={$row['product_id']}";?>>
        	<img src=<?php echo "./images/{$row['pix']}";?> border='0'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.