antonio12 Posted December 2, 2008 Share Posted December 2, 2008 Hello MySQL/PHP Experts I this piece of code and I can not seem to figure out why my images are not being displayed. I have the IMAGEURL link stored in my MySQL database. I have the FULL link stored in the database and it still will not display the image. Here is my short code: <?php // Make a MySQL Connection mysql_connect("IPADDRESS","databaseID","password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM producttable") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Product ID</th><th>IMAGE PICTURE</th> <th>Product Name</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['ProductID']; echo "</td><td>"; echo "<img src='<?= [imageURL] ?>' />"; echo "</td><td>"; echo $row['ProductName']; echo "</td></tr>"; } echo "</table>"; ?> Can someone help explain to me what I am doing wrong? Thank you in advance! Regards, Antonio Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/ Share on other sites More sharing options...
rhodesa Posted December 2, 2008 Share Posted December 2, 2008 echo "<img src='<?= [imageURL] ?>' />"; should be echo "<img src='{$row['imageURL']}' />"; Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/#findComment-704146 Share on other sites More sharing options...
antonio12 Posted December 2, 2008 Author Share Posted December 2, 2008 Thank you so much rhodesa!!! That fixed my problem! FINALLY!! After three hours of debugging.... I am a php newbie and this definitely solves more issues than just this piece of code... thanks again! Antonio Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/#findComment-704156 Share on other sites More sharing options...
antonio12 Posted December 2, 2008 Author Share Posted December 2, 2008 Rhodesa if you are out there - help one more time please! I can not seem to display the URL associated with each product name now. I have tried every which way but no luck! Please help! <?php // Make a MySQL Connection mysql_connect("IPADDRESS", "databasename","password") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM PRODUCTS") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Product ID</th><th>IMAGE PICTURE</th> <th>Product URL</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['ProductID']; echo "</td><td>"; echo "<img src='{$row['ImageURL']}' />"; echo "</td><td>"; echo "<a href='<?= {$row['BuyURL']} ?>'><?'{$row['ProductName']}'></</a>"; echo "</td></tr>"; } echo "</table>"; ?> Thanks again in advance. Regards, Antonio Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/#findComment-704283 Share on other sites More sharing options...
fenway Posted December 2, 2008 Share Posted December 2, 2008 Don't open a new topic for the same issue..... Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/#findComment-704354 Share on other sites More sharing options...
rhodesa Posted December 2, 2008 Share Posted December 2, 2008 ok...we need to cover some PHP basics...to print a variable you have a few options... if PHP is NOT started (aka, we are not in PHP tags) you can do the following: <table> <tr> <td>The common way:</td> <td><?php echo $variable; ?></td> </tr> <tr> <td>The shorthand way:</td> <td><?=$variable?></td> </tr> </table> now, in your case, PHP is already started (aka we are in PHP tags): echo "<table>"; echo "<tr>"; echo "<td>This way, we stop the string, print the variable, the start it again</td>"; echo "<td>".$variable."</td>"; echo "</tr>"; echo "<tr>"; echo "<td>This way, we put the variable inside the string, PHP will convert it to it's value for us:</td>"; echo "<td>$variable</td>"; echo "</tr>"; echo "<tr>"; echo "<td>But, with arrays, we need to put braces around it (you can do this for regular scalar variables too:</td>"; echo "<td>{$row['variable']}</td>"; echo "</tr>"; echo "</table>"; you are mixing the two methods. by using echo and <?={$row['BuyURL']}?>...just use one: echo "<a href='{$row['BuyURL']}'>{$row['ProductName']}</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/135200-isplay-product-name-with-product-url/#findComment-704378 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.