Lassie Posted August 4, 2008 Share Posted August 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/ Share on other sites More sharing options...
vikramjeet.singla Posted August 4, 2008 Share Posted August 4, 2008 try this: <?php echo "<a href=\"#\" onmouseover=\"ajax_showTooltip('demo-pages/js-calendar.html',this);return false\" onmouseout=\"ajax_hideTooltip()\">Info</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607368 Share on other sites More sharing options...
Lassie Posted August 4, 2008 Author Share Posted August 4, 2008 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 />"; Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607424 Share on other sites More sharing options...
Lassie Posted August 4, 2008 Author Share Posted August 4, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607660 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 echo it , dont just place it there Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607663 Share on other sites More sharing options...
Lassie Posted August 4, 2008 Author Share Posted August 4, 2008 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607672 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607678 Share on other sites More sharing options...
Lassie Posted August 4, 2008 Author Share Posted August 4, 2008 Hi Thanks. Sorry it still doesnt parse. Do i need to \ some where? Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607754 Share on other sites More sharing options...
lemmin Posted August 4, 2008 Share Posted August 4, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607757 Share on other sites More sharing options...
Lassie Posted August 4, 2008 Author Share Posted August 4, 2008 Ok I see that and still get the error. Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607780 Share on other sites More sharing options...
lemmin Posted August 4, 2008 Share Posted August 4, 2008 What exactly is the parse error you are getting? Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607868 Share on other sites More sharing options...
DeanWhitehouse Posted August 4, 2008 Share Posted August 4, 2008 add error_reporting(E_ALL); to the top of the page Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-607878 Share on other sites More sharing options...
Lassie Posted August 5, 2008 Author Share Posted August 5, 2008 The error is parse error,unexpected T_STRING, expecting ',' or "," in line 47 Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-608481 Share on other sites More sharing options...
lemmin Posted August 5, 2008 Share Posted August 5, 2008 Can you show the full code or a few more lines around line 47? Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-608682 Share on other sites More sharing options...
Lassie Posted August 5, 2008 Author Share Posted August 5, 2008 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'); }*/ Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-608712 Share on other sites More sharing options...
lemmin Posted August 5, 2008 Share Posted August 5, 2008 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' Quote Link to comment https://forums.phpfreaks.com/topic/118060-incorporate-javascript-call-into-php/#findComment-608738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.