justAnoob Posted May 7, 2009 Share Posted May 7, 2009 right now i have a line of code that says <?php echo '<img src="' . $row['imgpath2'] . '" width='125' alt="" />'; ?> I'm looking to put this in it's place.... <?php if(mysql_num_rows($img2query) > 0) { echo '<img src="' . $row['imgpath2'] . '" width='125' alt="" />'; } else { echo "No picture yet."; } ?> Can I echo an IF statement??? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Echo an if statement? Okay.. echo 'if (condition) { do_something(); }'; Quote Link to comment Share on other sites More sharing options...
shlumph Posted May 7, 2009 Share Posted May 7, 2009 What are you asking, justAnoob? Does your code not work? Or are you looking for something like this? (mysql_num_rows($img2query) > 0) ? print "image src, etc...." : print "No picture yet."; Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 thanks,,, just getting some ideas. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 keep getting error on this line..... <?php echo 'if(mysql_num_rows($img2query) > 0) { echo "<img src="' . $row['imgpath2'] . '" width='125' alt="" />"; // this line here } else { echo "No picture yet." }'; ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 if(mysql_num_rows($img2query) > 0)) i put the other ) on the line but still an error with the commented line... I notice that the comment did not turn yellow.... Quote Link to comment Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Change width='125' to be width="125" A simple syntax error. I would read up on PHP syntax and or invest in using a color coded PHP Editor. As that error really is plain to see. EDIT: You do realize that it will just print the actual statements. The smartass remark made about echoing if statements was because you chose your wording for the question very poorly. <?php if (mysql_num_rows($img2query) > 0) { echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; }else { echo "No picture yet."; } ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 smartass remark,,,, what are you talking about??? Does no one understand what I'm trying to do??? Quote Link to comment Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 smartass remark,,,, what are you talking about??? Does no one understand what I'm trying to do??? If you were being serious that you just want to "echo" and if statement then this would work: <?php echo 'if (mysql_num_rows($img2query) > 0) { echo \'<img src="' . $row['imgpath2'] . '" width="125" alt="" />\'; }else { echo "No picture yet."; }'; ?> Notice that you had width='125' which was wrong because you were echoing inside of single quotes. Changing it to width="125" should fix that. Are either of the solutions posted in Reply#6 or this reply the ones you are looking for? If not than no I do not understand at all what you are trying to do. EDIT: Fixed error. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 smartass remark,,,, what are you talking about??? Does no one understand what I'm trying to do??? If you were being serious that you just want to "echo" and if statement then this would work: <?php echo 'if (mysql_num_rows($img2query) > 0) { echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; }else { echo "No picture yet."; }'; ?> Notice that you had width='125' which was wrong because you were echoing inside of single quotes. Changing it to width="125" should fix that. Are either of the solutions posted in Reply#6 or this reply the ones you are looking for? If not than no I do not understand at all what you are trying to do. Syntax errors? And no, I personally have no idea what you want to do. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 I have a table that is echoed out with pictures in separate sections of the table.... Instead of just echoing the picture... like so <?php echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; ?> I want a script in place of that echo saying that if the image is in mysql,, then show the image.... and if there is no image,, then say that there is no image..... here is the rest of the script.... <?php session_start(); include "connection.php"; $findit = $_SESSION['id']; $result = mysql_query("SELECT id FROM members WHERE username = '$findit'"); $result = mysql_result($result, 0, 0); $sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM member_trades WHERE user_id = '$result'"); $img2query = mysql_query("SELECT imgpath2 FROM member_trades WHERE user_id = '$result'"); echo "<table width='954' height='523' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>"; while ($row = mysql_fetch_array($sql)) { echo "<tr><td width='188' height='180'><div align='center'>"; echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; //echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; // this was the original line that I had but it did not work as I wanted it to... this line would return just a empty box with a red x in it if there was no picture in mysql database... if (mysql_num_rows($img2query) > 0) { echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; } else { echo "No picture yet."; } echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />'; echo "</div></td><td width='190'><div align='center'>"; echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />'; echo "</div></td></tr><tr><td height='43' colspan='4'>"; echo '<strong>Item Name:</strong> ' . $row['item_name'] . ''; echo "</td><td><div align='center'>"; echo "previouse next buttons"; echo "</div></td></tr><tr><td height='116' colspan='4'>"; echo '<strong>Description:</strong> ' . $row['description'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td height='124' colspan='4'>"; echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td colspan='4'>"; echo "save delete buttons"; echo "</td><td><div align='center'>"; echo "</td></tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 So I should just be able to put my script inside the div and I should be ok right? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 <?php while ($row = mysql_fetch_array($sql)) { echo "<tr><td width='188' height='180'><div align='center'>"; echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />'; echo '</div></td><td width="188"><div align="center"> <?php if (mysql_num_rows($img2query) > 0) { echo "<img src="' . $row['imgpath2'] . '" width="125" alt="" />"; } else { echo "No picture yet."; } ?>'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />'; echo "</div></td><td width='190'><div align='center'>"; echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />'; echo "</div></td></tr><tr><td height='43' colspan='4'>"; echo '<strong>Item Name:</strong> ' . $row['item_name'] . ''; echo "</td><td><div align='center'>"; echo "previouse next buttons"; echo "</div></td></tr><tr><td height='116' colspan='4'>"; echo '<strong>Description:</strong> ' . $row['description'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td height='124' colspan='4'>"; echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td colspan='4'>"; echo "save delete buttons"; echo "</td><td><div align='center'>"; echo "</td></tr>"; } echo "</table>"; ?> Can I have a script inside a script?? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted May 7, 2009 Author Share Posted May 7, 2009 calling this solved although it is not... It is driving me crazy..... I got to this point... but it is still showing a box with a red x in it... When it should be saying "no picture here" <?php session_start(); include "connection.php"; $findit = $_SESSION['id']; $result = mysql_query("SELECT id FROM members WHERE username = '$findit'"); $result = mysql_result($result, 0, 0); $sql = mysql_query("SELECT imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM member_trades WHERE user_id = '$result'"); $img2query = mysql_query("SELECT imgpath2 FROM member_trades WHERE user_id = '$result'"); echo "<table width='954' height='523' border='1' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>"; while ($row = mysql_fetch_array($sql)) { echo "<tr><td width='188' height='180'><div align='center'>"; echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; if (mysql_num_rows($img2query) > 0) { echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" />'; } else { echo "No picture yet."; } echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" />'; echo "</div></td><td width='188'><div align='center'>"; echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" />'; echo "</div></td><td width='190'><div align='center'>"; echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" />'; echo "</div></td></tr><tr><td height='43' colspan='4'>"; echo '<strong>Item Name:</strong> ' . $row['item_name'] . ''; echo "</td><td><div align='center'>"; echo "previouse next buttons"; echo "</div></td></tr><tr><td height='116' colspan='4'>"; echo '<strong>Description:</strong> ' . $row['description'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td height='124' colspan='4'>"; echo '<strong>Item wanted or price:</strong> ' . $row['in_return'] . ''; echo "</td><td><div align='center'>"; echo "</div></td></tr><tr><td colspan='4'>"; echo "save delete buttons"; echo "</td><td><div align='center'>"; echo "</td></tr>"; } echo "</table>"; ?> 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.