Jump to content

Trying to integrate a shopping cart


The_Dude_1978

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.