The_Dude_1978 Posted August 23, 2011 Share Posted August 23, 2011 Hi guy's, I'm trying to integrate a shopping cart, but my knowledge is lacking. I've tried allot, but mostly it resulted in displaying nothing or a bunch of errors. Here's where i'm at. function getProducts() { //Function to display the products on the front end //Create the MYSQL db connection $db = new Connection(DB_HOST, DB_USER, DB_PASS, T4_DB_NAME); //Query the DB for all the products $result = $db->query('SELECT * FROM user_photos'); // for testing purposes //Set the items variable so that you can add to it in the loop below $items = ''; //Loop through the mysql results $id = $_GET['id']; $username = $_GET['username']; // NOTE: if i do a while here, it display's all pictures of every user and loops the pictures for 16 times. // If i do a if i can click the image, but the thumnail is not displaying and the title is that of the admin // and only one image is displayed, while a user has more pictures. while($row = mysql_fetch_assoc($result)) { $items .= ' <div class="product"> <h3>'.stripslashes($row['title']).'</h3> <div class="info"> <a href=/secure/users/'.$username .'/pics/'. stripslashes($row['reference']).'> <img src=/secure/users/'.$username .'/pics/thumbs/'. stripslashes($row['thumbnail']).'></a> <div class="price">€'.number_format($row['price'], 2).'</div> <a href="addToCart.php?ID='.$id.'">Add to cart</a> </div> </div> '; } echo $items; } See NOTE in code: // NOTE: if i do a while here, it display's all pictures of every user and loops the pictures for 16 times. // If i do a if i can click the image, but the thumnail is not displaying and the title is that of the admin // and only one image is displayed, while a user has more pictures. (id=1) while it should be 25. (title= that of the admin). (thumbnail not displaying) The username and path is correct, because when you click on the broken image it display's the bigger picture of the user who's logged in. Who is so kind to help me out here? Martijn Link to comment https://forums.phpfreaks.com/topic/245527-trying-to-integrate-a-shopping-cart/ Share on other sites More sharing options...
The_Dude_1978 Posted August 24, 2011 Author Share Posted August 24, 2011 Solved it on my own, thanks for reading function getProducts() { //Function to display the products on the front end //Create the MYSQL db connection $db = new Connection(DB_HOST, DB_USER, DB_PASS, T4_DB_NAME); //Set the items variable so that you can add to it in the loop below $items = ''; //Loop through the mysql results if($_GET['id']) { $sql="SELECT `id`, `first`, `last`, `username`, `email`, `about`, `level` from `users` WHERE `id` = '" . mysql_real_escape_string( $_GET [ "id" ]) . "'"; $res=mysql_query($sql); $row=mysql_fetch_assoc($res); { $sql2 = "SELECT `profile_id`, `title`, `size`, `type`, `thumbnail`, `reference`,`price` FROM user_photos WHERE profile_id = '" . mysql_real_escape_string( $_GET [ "id" ]) . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) > 0) { while($file = mysql_fetch_array($res2)) { $items .= ' <div class="product"> <h3>'.($file['title']).'</h3> <div class="info"> <a href=/secure/users/'.$_GET['username'].'/pics/'.($file['reference']).'> <img src=/secure/users/'.$_GET['username'].'/pics/thumbs/'.($file['thumbnail']).'></a> <div class="price">€'.number_format($file['price'], 2).'</div> <a href="addToCart.php?id='.$_GET['id'].'">Add to cart</a> </div> </div> '; } } echo $items; } } } Link to comment https://forums.phpfreaks.com/topic/245527-trying-to-integrate-a-shopping-cart/#findComment-1261538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.