[SOLVED] Adding additional values to a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

[SOLVED] Adding additional values to a variable

Post by tristanlee85 »

I'm trying to add some modifications to my phpBB site by getting information from a database on one of my other sites. It's pulling information correctly, but I'm having trouble adding more information to a variable. I actually so confused myself that it's going to be hard for me to explain this in propper terms.

Here is the code I have so far:

Code: Select all

$query1="SELECT * FROM xcart_products WHERE add_date < '$today_date' && add_date > '$minus_five_days'";
		$result1=mysql_query($query1);
		$numrows1=mysql_numrows($result1);
		//echo $numrows1;
			if ($numrows1 < 2)
				{
				$latest_prod = "Latest product: ";
				}
			else
				{
				$latest_prod = "Latest products: ";
				}
		$count = 0;
		while ($count < $numrows1)
			{
			$product=mysql_result($result1,$count,"product");
			//echo $product." - ";
			$product_id=mysql_result($result1,$count,"productid");
			//The above variables will be included in: <a href="http://store.plastikracing.net/product.php?	productid={PRODUCT_ID}" target="_blank">{PRODUCT}   <img src="http://store.plastikracing.net/product_images/t_{PRODUCT_ID}.jpg" width="50" height="38"></a><br> 
			$count++;
			}
Bascially, in that loop, there is a chance that "numrows1" is going to be greater than 1. Here is what I want to do. Let's say there is 1 row in the database that matches the criteria. The information pulled from that row will be inserted into a variable like so:

Code: Select all

$display_product = "<a href='http://store.plastikracing.net/product.php?productid=".$product_id." target='_blank'>".$product."<img src='http://store.plastikracing.net/product_images/t_".$product_id.".jpg' width='50' height='38'></a><br>";
Now, let's assume there are 2 products that match the criteria. I would like the 2nd product to be added to the end of the $display_product like so:

Code: Select all

$display_product = "<a href='http://store.plastikracing.net/product.php?productid=".$product_id[0]." target='_blank'>".$product[0]."<img src='http://store.plastikracing.net/product_images/t_".$product_id[0].".jpg' width='50' height='38'></a><br><a href='http://store.plastikracing.net/product.php?productid=".$product_id[1]." target='_blank'>".$product[1]."<img src='http://store.plastikracing.net/product_images/t_".$product_id[1].".jpg' width='50' height='38'></a><br>";
Does anyone have any suggestions? I was looking at using implode(), but I'm no too familiar with arrays.
Last edited by tristanlee85 on Mon Sep 04, 2006 12:20 am, edited 1 time in total.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

.=
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Hmm. I haven't a clue what you mean.
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Anyone? It'd be easy if I could simply echo everything out, but since I'm using it in phpBB, they use arrays for their templates so I have to combine all the outputs into 1 variable.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You realize that's shaving very very very close to being qualified as bumping, right?

Look in the operators pages of the manual for an explanation of what Jenk posted about.

http://php.net/language.operators
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Code: Select all

$display_product;
		while ($count < $numrows1)
			{
			$product=mysql_result($result1,$count,"product");
			//echo $product." - ";
			$product_id=mysql_result($result1,$count,"productid");
			$display_product .= "<a href='http://store.plastikracing.net/product.php?productid=".$product_id." target='_blank'>".$product."<img src='http://store.plastikracing.net/product_images/t_".$product_id.".jpg' width='50' height='38'></a><br>"; 
			$count++;
			}
Post Reply