justAnoob Posted December 22, 2009 Share Posted December 22, 2009 I posted this is the js section and I was told it was for the PHP section Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING <script language="JavaScript"> image0.src ="<?php echo $row['imgpath']; ?>" </script Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 try using it like this <script language="JavaScript"> image0.src ="<?php echo "$row['imgpath']"; ?>" </script Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 There is nothing syntactically wrong with that code, can we see more code surrounding? Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 try using it like this <script language="JavaScript"> image0.src ="<?php echo "$row['imgpath']"; ?>" </script Now, that IS syntactically incorrect. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 try using it like this <script language="JavaScript"> image0.src ="<?php echo "$row['imgpath']"; ?>" </script Now, that IS syntactically incorrect. i know that it is wrong, as he doesnot gave more info.. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Why would you knowingly post incorrect code for someone to use? Makes no sense. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 Just posting up the important sutff I have one div which shows a full size image. And smaller divs which show the thumbnail. on mouseover of the thumbs, the full size is displayed in the bigger div . $row['imgpath'] should always show in the bigger div until mouseover of the other thumbs. <?php $sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5 FROM member_pictures WHERE thumb_1 = " . $_SESSION['picposted'] . ""); $result=mysql_query($sql); ?> script language="JavaScript"> <!-- //thumbnail script image0 =new Image(); image1 =new Image(); image2 =new Image(); image3 =new Image(); image4 =new Image(); // This defines the source of the display image image0.src ="<?php echo $row['imgpath']; ?>" image1.src ="<?php echo $row['imgpath2']; ?>" image2.src ="<?php echo $row['imgpath3']; ?>" image3.src ="<?php echo $row['imgpath4']; ?>" image4.src ="<?php echo $row['imgpath5']; ?>" // This defines the source of the preview image document.images['pimage0'].src=image0.src; document.images['pimage1'].src=image1.src; document.images['pimage2'].src=image2.src; document.images['pimage3'].src=image3.src; document.images['pimage4'].src=image4.src; // This defines what to do when an image is clicked on function image_click(clicks) { if(clicks==0){document.images['large'].src=image0.src;} if(clicks==1){document.images['large'].src=image1.src;} if(clicks==2){document.images['large'].src=image2.src;} if(clicks==3){document.images['large'].src=image3.src;} if(clicks==4){document.images['large'].src=image4.src;} } // --></script> <div align="center"><img src="<?php echo "$row['imgpath']"; ?>" align="middle" border="0" width="380 height="225" name="large"></div> <div align="center"> <a onmouseover="javascript:image_click(0)"><img src="<?php echo "$row['thumb_1']"; ?>" width="90" height="80" name="pimage0" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo "$row['thumb_2']"; ?>" width="90" height="80" name="pimage1" border=0></a> </div> .....................and so on Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 i think in this one u have an error <div align="center"><img src="<?php echo "$row['imgpath']"; ?>" align="middle" border="0" width="380 height="225" name="large"></div> <div align="center"> <a onmouseover="javascript:image_click(0)"><img src="<?php echo "$row['thumb_1']"; ?>" width="90" height="80" name="pimage0" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo "$row['thumb_2']"; ?>" width="90" height="80" name="pimage1" border=0></a> </div> .....................and so on remove the "" after echo.. like this <div align="center"><img src="<?php echo $row['imgpath']; ?>" align="middle" border="0" width="380 height="225" name="large"></div> <div align="center"> <a onmouseover="javascript:image_click(0)"><img src="<?php echo $row['thumb_1']; ?>" width="90" height="80" name="pimage0" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo $row['thumb_2']; ?>" width="90" height="80" name="pimage1" border=0></a> </div> .....................and so on Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 All these.... <?php echo "$row['imgpath']"; ?> should be.... <?php echo $row['imgpath']; ?> Otherwise, I don't see anything wrong. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 Here is the all the code. I just left out the CSS <?php error_reporting(E_ALL); ini_set('display_errors',1); session_start(); include_once 'header.php'; include "connection.php"; $sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5,FROM member_pictures WHERE thumb_1 = " . $_SESSION['picposted'] . ""); $result=mysql_query($sql); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <script language="JavaScript"> <!-- //thumbnail script image0 =new Image(); image1 =new Image(); image2 =new Image(); image3 =new Image(); image4 =new Image(); // This defines the source of the display image image0.src ="<?php echo $row['imgpath']; ?>" image1.src ="<?php echo $row['imgpath2']; ?>" image2.src ="<?php echo $row['imgpath3']; ?>" image3.src ="<?php echo $row['imgpath4']; ?>" image4.src ="<?php echo $row['imgpath5']; ?>" // This defines the source of the preview image document.images['pimage0'].src=image0.src; document.images['pimage1'].src=image1.src; document.images['pimage2'].src=image2.src; document.images['pimage3'].src=image3.src; document.images['pimage4'].src=image4.src; // This defines what to do when an image is clicked on function image_click(clicks) { if(clicks==0){document.images['large'].src=image0.src;} if(clicks==1){document.images['large'].src=image1.src;} if(clicks==2){document.images['large'].src=image2.src;} if(clicks==3){document.images['large'].src=image3.src;} if(clicks==4){document.images['large'].src=image4.src;} } // --></script> </head> <body> <table width="954" border="0" align="center"> <tr> <td height="702"> <div id="PictureBox"> <div id="divvy"> <span class="bigger"> Your picture has been posted - </span> <span class="different">Picture Preview<span class="goto_around"> (goto </span></span><span class="style1"><span class="style3"><a href="http://www.mysite.com/example.php" class="goto">Active Pictures</a></span></span><span class="different"><span class="goto_around"> to add pictures)</span></span><br /> <div id="postnew"> <table width="705" bordercolor="#000000" bgcolor="#9AA4AD" id="table"> <tr> <td> <table width="400" border="1" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td colspan="4"><div align="center"><img src="<?php echo "$row['imgpath']"; ?>" align="middle" border="0" width="380 height="225" name="large"></div></td> </tr> <tr> <td colspan="4"> <div align="center"> Mouse over thumbnails to view larger image. </div> </td> </tr> <tr> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(0)"><img src="<?php echo "$row['thumb_1']"; ?>" width="90" height="80" name="pimage0" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo "$row['thumb_2']"; ?>" width="90" height="80" name="pimage1" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(2)"><img src="<?php echo "$row['thumb_3']"; ?>" width="90" height="80" name="pimage2" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(3)"><img src="<?php echo "$row['thumb_4']"; ?>" width="90" height="80" name="pimage3" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(4)"><img src="<?php echo "$row['thumb_5']"; ?>" width="90" height="80" name="pimage4" border=0></a> </div> </td> </tr> </table> </td> </tr> </table> </div> </div> </div> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 change this <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo "$row['thumb_2']"; ?>" width="90" height="80" name="pimage1" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(2)"><img src="<?php echo "$row['thumb_3']"; ?>" width="90" height="80" name="pimage2" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(3)"><img src="<?php echo "$row['thumb_4']"; ?>" width="90" height="80" name="pimage3" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(4)"><img src="<?php echo "$row['thumb_5']"; ?>" width="90" height="80" name="pimage4" border=0></a> </div> </td> </tr> </table> like <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(1)"><img src="<?php echo $row['thumb_2']; ?>" width="90" height="80" name="pimage1" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(2)"><img src="<?php echo $row['thumb_3']; ?>" width="90" height="80" name="pimage2" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(3)"><img src="<?php echo $row['thumb_4']; ?>" width="90" height="80" name="pimage3" border=0></a> </div> </td> <td bordercolor="#FFFFFF"> <div align="center"> <a onmouseover="javascript:image_click(4)"><img src="<?php echo $row['thumb_5']; ?>" width="90" height="80" name="pimage4" border=0></a> </div> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 If that is all the code, I don't see where $row is even defined. Is it? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 just changed it whle you were probably typing changed $result=mysql_query($sql); to this $row = mysql_fetch_array($sql) Now this. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource One day I think i understand it, next day I'm confused Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 mysql_fetch_array() expects a result resource which is what mysql_query() returns. if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); // rest of your code should go here. } } Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 wo, what? sorry. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 I'm not sure how it could be explained any simpler. mysql_fetch_array() expects a result resource which is what mysql_query() returns. The ifs and check against mysql_num_rows() are there to prevent errors. You should always check your results before attempting to use them. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 I'm not sure how it could be explained any simpler. mysql_fetch_array() expects a result resource which is what mysql_query() returns. The ifs and check against mysql_num_rows() are there to prevent errors. You should always check your results before attempting to use them. sorry i too didnt got it so do mean that without if condition mysql_fetch_array() doesnot work Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 Actually, just the part where you say that the rest of the code goes here. I'm sorry, I'm not just looking for someone to give me the answer. I would still like to understand it. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 I'm not sure how it could be explained any simpler. mysql_fetch_array() expects a result resource which is what mysql_query() returns. The ifs and check against mysql_num_rows() are there to prevent errors. You should always check your results before attempting to use them. sorry i too didnt got it so do mean that without if condition mysql_fetch_array() doesnot work If there are no results there's no point passing an empty result resource to mysql_fetch_assoc(). Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Actually, just the part where you say that the rest of the code goes here. I'm sorry, I'm not just looking for someone to give me the answer. I would still like to understand it. Given my code above, the part where I sat '// rest of your code should go here'. That is the only place where $row is defined and guaranteed to have data. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 got it. I think. I try a few things. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 i think the error is in the query $sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5 FROM member_pictures WHERE thumb_1 = " . $_SESSION['picposted'] . ""); try running the query in the mysql and see what result u get by the way wht is the $_SESSION['picposted'] value Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 Nope, totally confused now. And wondering if the general way I have the code will even work at all, or if I should change everything. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 22, 2009 Share Posted December 22, 2009 Nope, totally confused now. And wondering if the general way I have the code will even work at all, or if I should change everything. just try running the query in the mysql and see if u can get any results. if not then use the code which has been given by thrope Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 I don't see anything wrong with the query or the logic here. Whats the problem now? Quote Link to comment 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.