justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 Here is my table the is suppose to be displayed. But is not. No table is displayed and also in the error console of FF I get an "unterminated string literal" which points to this below. 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']; ?>" <?php include "connection.php"; $sql = mysql_query("SELECT id, 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); if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); ?> <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> <?php } } ?> </td> </tr> </table> </div> </div> </div> </td> </tr> </table> I'm pretty sure that I am displaying the table correctly. I have done this before. Maybe something is wrong though. I'm stumped. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 22, 2009 Share Posted December 22, 2009 what is this whole mess here: <?php //... $result=mysql_query($sql); if ($result = mysql_query($sql)) { lose the: $result=mysql_query($sql); and: if ($result = mysql_query($sql)) { you have already executed your query with this: $sql = mysql_query ("..."); you don't need to execute the query 3 times. code will look like this now: <?php include "connection.php"; $sql = mysql_query("SELECT id, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5 FROM member_pictures WHERE thumb_1 = " . $_SESSION['picposted'] . ""); if (mysql_num_rows($sql) > 0) { $row = mysql_fetch_array($sql); ?> <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> <?php } ?> </td> </tr> </table> </div> </div> </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 The execution of mysql_query() should always be wrapped within an if statement to prevent errors being displayed if it fails. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 22, 2009 Share Posted December 22, 2009 hey, this ain't my code. this will not work: if ($result = mysql_query($sql)) and was the reason for no output. EDIT: had proper error handling (adding an ELSE condition to each IF), this would have been picked up ages ago. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 hey, this ain't my code. this will not work: if ($result = mysql_query($sql)) and was the reason for no output. EDIT: had proper error handling (adding an ELSE condition to each IF), this would have been picked up ages ago. That is my code and it does work. In fact that is how all select queries should be written, this way you know $result holds a result resource prior to passing it to mysql_num_rows() or mysql_fetch_assoc(). See here. Quote Link to comment Share on other sites More sharing options...
teynon Posted December 22, 2009 Share Posted December 22, 2009 Thorpe... If statements don't block mysql warnings... @'s do. If is a good thing to always do on a mysql query, though because it's never certain to work. "if (@mysql_query" Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Thorpe... If statements don't block mysql warnings... @'s do. If is a good thing to always do on a mysql query, though because it's never certain to work. "if (@mysql_query" I know how mysql_query works. Point is, you need to check your $result before passing it to any of the other mysql functions. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 if ($result = mysql_query($sql)) = nothing displayed and if (mysql_num_rows($sql) > 0) = nothing displayed Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 Then you don't have any records matching your query. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted December 22, 2009 Share Posted December 22, 2009 k, but the comparison operator is incorrect. should be === (or at least ==), but you're best to check type as well. instead of: if ($result = mysql_query($sql)) if ($sql) would suffice. OR: if ($result === mysql_query ($sql)) now, i'm not trying to be of a disturbance, and i see you are of Alumni status, so respect is given where respect is due, but that code has redundancies: one with mysql_query function being called twice: $sql = mysql_query("..."); $result=mysql_query($sql); Quote Link to comment Share on other sites More sharing options...
justAnoob Posted December 22, 2009 Author Share Posted December 22, 2009 alright, i threw some info into the query to make sure it works and it does. So I'll go back and check my variables. Quote Link to comment Share on other sites More sharing options...
trq Posted December 22, 2009 Share Posted December 22, 2009 k, but the comparison operator is incorrect. should be === (or at least ==), but you're best to check type as well. instead of: if ($result = mysql_query($sql)) if ($sql) would suffice. OR: if ($result === mysql_query ($sql)) now, i'm not trying to be of a disturbance, and i see you are of Alumni status, so respect is given where respect is due, but that code has redundancies: one with mysql_query function being called twice: $sql = mysql_query("..."); $result=mysql_query($sql); I never told the OP to execute mysql_query more than once. That was there mistake. Using a comparison operator would fail to assign the result to $result, where not trying to do a comparison. Just checking the expression equates to true. Quote Link to comment Share on other sites More sharing options...
Nom Nom Posted December 23, 2009 Share Posted December 23, 2009 It basically puts the results in an array like $row['column_name'] = "field"; 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.