Jump to content

PHP explode conundrum.


HCProfessionals

Recommended Posts

I'm trying to add options to products.

 

Currently, I have them in this format: Leather reinforced hilt,5.00::Stabbing tip,3.00::Logo,10.00

 

$option_results = mysql_query("SELECT product_options FROM products WHERE product_id='".$product."'");
   while($option_row = mysql_fetch_array($option_results)){
         $option = explode("::", $option_row[0]);
         $option_part = explode(",", $option[0]);
         $option_part[0] = $option_name;
         $option_part[1] = $option_price;
         echo "<li><a href=\"#\">".$option_name.", Add $".$option_price."</a></li>";
    }

 

I would like the output to be:

 

<li><a href="#">Leather reinforced hilt, Add $5.00</a></li>

<li><a href="#">Stabbing tip, Add $3.00</a></li>

<li><a href="#">Logo, Add $10.00</a></li>

Link to comment
https://forums.phpfreaks.com/topic/260260-php-explode-conundrum/
Share on other sites

I'm not really getting anywhere...

 

					$option_results = mysql_query("SELECT product_options FROM products WHERE product_id='".$product."'");
					while($option_row = mysql_fetch_array($option_results)){
							$sep_option = explode("::", $option_row[0]);
							foreach ($sep_option as $sep_result)
							{
								$option_part = explode(",", $sep_result);
								$option_part[0] = $option_name;
								$option_part[1] = $option_price;
								echo "<li class=\"product\" id=\"option-".$option_name."\"><input class=\"purchase\" type=\"button\" value=\"Add to cart\"><span class=\"title\">".$option_name."</span>, Add $<span class=\"price\">".$option_price."</span></li>";
							}

					}

As was said before, you're not defining $option_name or $option_price. You're doing those statements backwards, you're saying that the first key in $option_part should be set to the value within $option_name. $option_name does not exist. Switch it around.

As was said before, you're not defining $option_name or $option_price. You're doing those statements backwards, you're saying that the first key in $option_part should be set to the value within $option_name. $option_name does not exist. Switch it around.

 

Wow, totally missed that. Thank You!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.