daniel28138 Posted January 21, 2014 Share Posted January 21, 2014 Okay, I thought I had this down to what I'm trying to do. But I can't find where I'm going wrong. I promise I searched the best I could, but I can't find specifically where the error (500) is coming from. This is what I added, without it, I get no error, but I get no echo of what I'm wanting either. echo "<tr><td><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">This Review Is About:</font></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\" size=\"4\"><b>{$band['Name']}</b></font></br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">Review Posted:</br></font><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FFFFFF\" size=\"2\"> ".date("F j, Y g:i a", strtotime($band["timestamp"]))."</font> </br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br> <font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF0000\" size=\"2\">ITR Rating:</font> if($band['rating']=='0'){ echo "<img src='../ratings/0star.png'/>"; } elseif($band['rating']=='1'){ echo "<img src='../ratings/1star.png'/>"; } elseif($band['rating']=='2'){ echo "<img src='../ratings/2star.png'/>"; } elseif($band['rating']=='3'){ echo "<img src='../ratings/3star.png'/>"; } elseif($band['rating']=='4'){ echo "<img src='../ratings/4star.png'/>"; } elseif($band['rating']=='5'){ echo "<img src='../ratings/5star.png'/>"; } </td>"; People on here have been great with help, and it's always very much appreciated. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 21, 2014 Share Posted January 21, 2014 (edited) You're not ending/starting the echo before/after the if/elseif condition, speaking of which that could be coded as one line echo "<tr><td><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">This Review Is About:</font></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\" size=\"4\"><b>{$band['Name']}</b></font></br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">Review Posted:</br></font><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FFFFFF\" size=\"2\"> ".date("F j, Y g:i a", strtotime($band["timestamp"]))."</font> </br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br> <font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF0000\" size=\"2\">ITR Rating:</font> <img src='../ratings/{$band['rating']}star.png'/> </td>"; Edited January 21, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
daniel28138 Posted January 22, 2014 Author Share Posted January 22, 2014 Ch0cu3r Thank you for the reply. But I think what you have just displays one image. I want it to show the image, based on the number (1 through 5) that is entered in the database. So if 1 is in the database for that row, then it will show 1star.png... if 3 is in the database for that row, then it will show 3star.png... etc. I have the images for each already uploaded. Quote Link to comment Share on other sites More sharing options...
daniel28138 Posted January 22, 2014 Author Share Posted January 22, 2014 I'd like to add that I am learning a lot mainly from the help I get on this forum. I appreciate it. I added a }else{echo "<img src='../ratings/0star.png'/>";} at the end but it didn't help Quote Link to comment Share on other sites More sharing options...
daniel28138 Posted January 22, 2014 Author Share Posted January 22, 2014 Oooookay. I think I made progress, but now I'm baffled as to why it only works outside the php I already have.... Here is where the ratings part works. And the second part will explain where I'm trying to put it. <table bgcolor=\"#333333\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"> <tr> <td> <?php $link = mysql_connect('site', 'db', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(bands); $query = "SELECT * FROM band ORDER BY `Name` ASC"; $res = mysql_query($query) or die(mysql_error()); while ($band = mysql_fetch_array($res)){ // Show images if($band['rating']=='0'){ print "<img src='../ratings/0star.png'/>"; } elseif($band['rating']=='1'){ print "<img src='../ratings/1star.png'/>"; } elseif($band['rating']=='4'){ print "<img src='../ratings/4star.png'/>"; } } // End while loop ?> </td> </tr> </table> <?php $link = mysql_connect('site', 'db', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(bands); $query = "SELECT * FROM band ORDER BY `Name` ASC"; $res = mysql_query($query) or die(mysql_error()); { function makeLinks($text) { $text = html_entity_decode(' '.$text); $text = preg_replace('#(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~\#?&//=]+)#', '<a href="\\1" target=_blank>\\1</a>', $text); $text = preg_replace('#([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~\#?&//=]+)#', '\\1<a href="http://\\2" target=_blank>\\2</a>', $text); $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1" target=_blank>\\1</a>', $text); $text = str_replace(array("\r\n", "\r", "\n"), "<br />", $text); return trim($text); } while ($band = mysql_fetch_assoc($res)) { echo "<table width=\"30%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\">"; $link = makeLinks($band['website']); $description = makeLinks($band['Description']); echo "<tr>"; echo "<td>"; echo "<table bgcolor=\"#333333\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">"; echo "<tr><td><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">This Review Is About:</font></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\" size=\"4\"><b>{$band['Name']}</b></font></br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">Review Posted:</br></font><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FFFFFF\" size=\"2\"> ".date("F j, Y g:i a", strtotime($band["timestamp"]))."</font> </br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br> <font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"00A0E0\" size=\"2\"><b>ITR Rating:</b></font> // Begin Rating // End Rating </td>"; echo "<td><div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\"><img src=\"bandimages/{$band['photo']}\" width=\"300\"> </div></td></tr>"; echo "</table>"; echo "<tr><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"00A0E0\" size=\"2\">Website:</font><span class=\"class5\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">{$link}</font></span></br></td></tr>"; echo "<tr bgcolor=\"#191919\"><td><div align=\"center\"><span class=\"class5\"><font face=\"Verdana, Arial, Helvetica, sans-serif\">{$description}</font></span></div></td></tr>"; echo "<tr>"; echo "<td>"; echo "<table bgcolor=\"#333333\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">"; echo "<tr><td><div align=\"center\"><span class=\"class1\"><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=\"modifybands.php?id={$band['id']}\"> Modify Review</a></font></span></div></td>"; echo "<td><div align=\"center\"><span class=\"class1\"><font face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=\"deletebands.php?id={$band['id']}\"> Delete Review</a></font></span></div></td></tr>"; echo "</table>"; echo "</table>"; echo "<div align=\"center\"><img src=\"http://www.inthisreview.com/Misc/tablespacer01.jpg\">"; } } ?> Now... here is the baffeling part. I've tried to ECHO to table so this can be part of the other loop. But as soon as I put it in the rest, I get the dredded 500 error again. If I have it like above, then I can see the script working, but it wont go as it is in the rest of the PHP (Note where I have //Start of rating - // End of rating) without the page error. This is the part (below) that works outside of the php script <table bgcolor=\"#333333\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"> <tr> <td> <?php $link = mysql_connect('site', 'db', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(bands); $query = "SELECT * FROM band ORDER BY `Name` ASC"; $res = mysql_query($query) or die(mysql_error()); while ($band = mysql_fetch_array($res)){ // Show images if($band['rating']=='0'){ print "<img src='../ratings/0star.png'/>"; } elseif($band['rating']=='1'){ print "<img src='../ratings/1star.png'/>"; } elseif($band['rating']=='4'){ print "<img src='../ratings/4star.png'/>"; } } // End while loop ?> </td> </tr> </table> And I want to get that into between the // Start rating and // End of rating Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 22, 2014 Share Posted January 22, 2014 the http 500 error is because you have a php (syntax) error in your code. in a previous thread, it was suggested to turn on php's error_reporting/display_errors (to get php to help you.) the reason no one replied when you asked what/how to do that is because the suggestion is a common activity that you are expected to search for the answer yourself, not just immediately ask without trying. Â if you look at your posted code at the start of this thread, you will notice that the forum software has color coded the different contexts it found and the php if() ... code has the same color highlighting as the php string, meaning your php string isn't terminated and is trying to make the php if()... code part of that string (your programming editor should have similar color highlighting to help you see differences/changes or lack of in the context of the code.) Â you need to go back and reread post #2 as many times as necessary until you understand what was stated and what the code is doing. it both corrected the string syntax and it performs the logic that your code needs. you could also test the code that was given to see what it actually does for the range of $band['rating'] input values. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 22, 2014 Share Posted January 22, 2014 (edited) Ch0cu3r Thank you for the reply. But I think what you have just displays one image. I want it to show the image, based on the number (1 through 5) that is entered in the database. So if 1 is in the database for that row, then it will show 1star.png... if 3 is in the database for that row, then it will show 3star.png... etc. I have the images for each already uploaded. I think you have misunderstood my reply. The following code does exactly that echo "... <img src='../ratings/{$band['rating']}star.png'/> ..."; Your if/elseif condition only outputs one image for any case. And you are statically defining the image path for each case 0 through to 5. My code dynamically defines the image using one line of code. it is concatenating the rating into the image path. So if $band['rating'] has the value of 3 then it return /ratings/3start.png, if its 0 it'll return /ratings/0star.png  below is your fixed code from your first post   echo "<tr><td><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">This Review Is About:</font></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF6633\" size=\"4\"><b>{$band['Name']}</b></font></br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"CCCCCC\" size=\"2\">Review Posted:</br></font><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FFFFFF\" size=\"2\"> ".date("F j, Y g:i a", strtotime($band["timestamp"]))."</font> </br><img src=\"http://www.inthisreview.com/Misc/tablespacersm01.png\"></br> <font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"FF0000\" size=\"2\">ITR Rating:</font>"; // END this echo BEFORE the if/elseif if($band['rating']=='0'){ echo "<img src='../ratings/0star.png'/>"; } elseif($band['rating']=='1'){ echo "<img src='../ratings/1star.png'/>"; } elseif($band['rating']=='2'){ echo "<img src='../ratings/2star.png'/>"; } elseif($band['rating']=='3'){ echo "<img src='../ratings/3star.png'/>"; } elseif($band['rating']=='4'){ echo "<img src='../ratings/4star.png'/>"; } elseif($band['rating']=='5'){ echo "<img src='../ratings/5star.png'/>"; } // START this echo AFTER the if/elseif echo "</td>";   Edited January 22, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
daniel28138 Posted January 22, 2014 Author Share Posted January 22, 2014 (edited) mac_gyver, my apologies. I never did explain further why I couldnt turn on the stuff to show me more specifically. I searched around but I couldn't seem to be able to duplicate what I saw to do that. I contacted my hosting company about it and they currently have a support ticket to find out why, so I'm waiting on that. Â Ch0cu3r You are awesome too. I appreciate that. And again, myapologies because I didn't explain further. I actually left out a huge chunk of what I needed. I actually see exactly why you're code works and thats great (It's echo'ing the number in the database and putting it as the beginning of the name of the png file to make it the full name of the image file - though my termonology is prob amateur sounding) The problem is, that there will be times I'll need this script, and the file name will be totally different from that. Another words, I will have pages where I'll use this, where... for example... the number "5" in the column will need to show image "random_image.jpg"or, the number 20 in the column will need to display the image "abottleofwhiskey.gif" etc etc. So I was using this to learn how to do the rest of them. Â For an example to show how I'm using this to learn, I have the "0" actually needing to display the image "nostar" so, "0star.png", is no image. Â I hope you all know that I do appreciate the help. I come here after I search and spend many hours trying it, so as to I don't feel like I'm just having someone build my site for me. Edited January 22, 2014 by daniel28138 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 22, 2014 Share Posted January 22, 2014 (edited) If you have numbers assigned to what images to display you can still do away with the ifelse/if.  You could set up an array of images assigned to numbers, eg $rating_images = array( 0 => 'nostar.jpg', ... 5 => 'random_image.jpg', ... 20 => 'abottleofwhisky.gif', ... ); Then to output the image you'd do echo "... <img src='../ratings/{$rating_images[ $band['rating'] ]}'/> ..."; Here $band['rating'] is being used as the array key for images. The matching key will then return the image. Edited January 22, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
daniel28138 Posted January 22, 2014 Author Share Posted January 22, 2014 AHHHHHHHHHHHHHHHHHH I see now!!! I can identify that the value equals the image, before it goes to display it. Sweet! See I love this site. I'm learning a lot. Thank you very much!!! 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.