So what your saying is, if someone has access to this code, they already will have access to a multitude of others equally sensitive as well?
Id eventually then, like to make this more secure by linking/inserting php via the inside of root folder theory, but thats something Id just have to see examples of as well.
BTW, I did learn a lot here. Thanks again!
Code:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "loginName", "loginPassword") or die(mysql_error());
mysql_select_db("zencartDBname") or die(mysql_error());
// Get all the data from the "products" table filtered by only those with 1 or more quantity, thus sold out items do not appear, also products set to disabled are not shown via status of 1. I only wanted images to be displayed, thus the product_image filter with wildcard. And finally, I wanted the newest products to be displayed first, so the order by ascending was inserted.
$result = mysql_query("SELECT * FROM products WHERE products_quantity >'0' AND products_status ='1' AND products_image LIKE'folderforimages/%' ORDER BY products_id='asc'")
or die(mysql_error());
//this is the html part. It declares a table with rows and also links, plus the size of images are controlled via inline style. Its kinda tricky to work with this because anytime you use a double quote symbol, it MUST BE escaped by placing a backslash prior to the double quote. Also you mush think in terms of where your code will be sort of cut off by the inserted urls from DB..
echo "<table border='0'>";
echo "<tr> <th><a href=\"http://www.yourdomain.com/zencart/index.php\">Available Now!</a></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><a href=\"http://www.yourdomain.com/zencart/index.php\"><img style=\"width:100px;padding-bottom:5px;\" src=\"http://www.yourdomain.com/zencart/images/";
echo $row['products_image'];
echo "\"></a></td><td>";
}
echo "</table>";
?>
OK, so thats my solution to get my latest product images to display vertically in a table with rows for each image at 100px wide, 5px padding, plus encapsulated by a link to my live products page, because it serves as a static "ad" on a different page than my zencart is located, however, both DO reside on the same domain.
Im sure it could be done differently, cleaner perhaps...but it does work for what I needed. Your situations may vary and I really would like to add something to limit the displayed results, whereas the above code does not..it displays all items that currently reside in the products table, that have more than one quantity, are not disabled, and are located in the specified images folder. If you had a lot of items available at one time (which for my situation here, I only have a few)...you WOULD need to specify some arbitrary limit to the amount of results that were displayed.
Bookmarks