Jump to content

mrooks1984

Members
  • Posts

    82
  • Joined

  • Last visited

    Never

Posts posted by mrooks1984

  1. thanks for your reply, i have tried this, but only the first field is changed in the database.

    	function post_update_variation_value() {
    
    	$option_id = mysql_real_escape_string($_POST['option_id']);
    	$variation_id = mysql_real_escape_string($_POST['variation_id']);
    	$product_name = mysql_real_escape_string($_POST['product_name']);
    
    	foreach ($_POST['title'] as $key => $value) {
      		$title = $value;
      		$price = $_POST['price'][$key];
    
      		// execute your query
    	$sql = "UPDATE store_option$variation_id SET title = '$title', price = '$price' WHERE id = '$key'";
    	$res = mysql_query($sql) or die(mysql_error());
    	}
    	echo '<script>window.location="dashboard.php?page=store_variation"</script>';
    }
    }
    

  2. if i use this code, i get this message: Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\jubileeleather\site\admin\_class\store.php on line 654

     

    	$option_id = mysql_real_escape_string($_POST['option_id']);
    	$variation_id = mysql_real_escape_string($_POST['variation_id']);
    	$product_name = mysql_real_escape_string($_POST['product_name']);
    
    	foreach($_POST['title'] as $key1 => $value1){
    
    		foreach($_POST['price'] as $key2 => $value2){
    
    			foreach($_POST['option_value_id'] as $key3 => $value3){
    
    				$sql = "UPDATE store_option$variation_id SET title = '$value1', price = '$value2' WHERE id = '$value3'";
    				$res = mysql_query($sql) or die(mysql_error());
    			}
    		}
    	}
    	echo '<script>window.location="dashboard.php?page=store_variation"</script>';
    }
    

  3. hello, i am hoping someone can help, i have multiple post results that need to go one by one into a table

     

    heres the form i have:

    	echo '<h2>Update Variation Values</h2>';
    	echo '<div id ="content_form">';
    	echo '<form method="post" action="">';
    	echo '<input type="hidden" name="option_id" value="' . $option_id . '">';
    	echo '<input type="hidden" name="variation_id" value="' . $variation_id . '">';
    	echo '<input type="hidden" name="product_name" value="' . $product_name . '">';
    	$sql = "SELECT * FROM store_option$variation_id WHERE product = '$product_name'";
    	$res = mysql_query($sql) or die(mysql_error());
    	while ($row = mysql_fetch_assoc($res)) {
    
    		echo '<div id="content_title"><label for="title[]">Title:</label></div>';
    		echo '<div id="content_box"><input name="title[]" type="text" id="title" value="' . $row['title'] . '" /></div>';
    		echo '<div id="content_title"><label for="price[]">Price:</label></div>';
    		echo '<div id="content_box"><input name="price[]" type="text" id="price[]" value="' . $row['price'] . '" /></div>';
    	}
    	echo '<div id="content_body"><input type="submit" name="post_update_variation_value" value="Save Values"></div></form>';
    	echo '</div>';
    }
    

    heres my current code

    	echo '<pre>',print_r($_POST,true);
    
    foreach($_POST['title'] as $key => $value){
    if($value !=''){
    
    	$sql = "UPDATE store_option$variation_id SET title = '$value', price = '$price' WHERE product = '$product_name'";
    	$res = mysql_query($sql) or die(mysql_error());
    } else {
    	echo "Option $key is empty<br />";
    }
    }
    

    its currently just doing the last result and filling up the database with that result, many thanks all.

     

  4. thanks for your responce, the issue is with this code it sometimes only has one value in the post see the code below.

     

    		//Get option values
    		foreach($_POST['option_value'] as $key => $value){
    			if($value !=''){	
    				$product_option_values[] = array("option_value" => $value);
    			}
    		}
    

     

    so if i replicate this from your code:

    $arr_title = array("Colours","Values","Test","Something else");
    $arr_opt  = array("Black","76");
    
    $arr_res = array_combine($arr_title, $arr_opt); 
    
    foreach ($arr_res as $key => $value) {
        if($value == ''){ // skip empty values
        continue;
        }
        echo "Title: ".$key."\n"."Value: ".$value.'<br />';
    }
    i get this error: 
    Warning: array_combine(): Both parameters should have an equal number of elements in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 237
    
    this is the main issue, is sometimes the values has less results then the title, so needs to unstead of looping the one value around all the titles, is just to stop when there isnt any more values.
    

  5. hello jesirose this was my code before, all i want it to do is stop looping when there are no values left, it currently get values from a form and puts the results into 2 arrays one is a list of all the titles ($product_option_title) and one is all the values ($product_option_value), the values are selected from a drop down menu, so sometimes there is less values then titles, but sometimes the values and the titles are the same.

    so again if say the values is black, the titles are color and size, if only color is selected in the drop down menu the value would only have the value black. So what it needs to do is go right there is only black in the value, get the title then stop the loop, instead of going color black, size black.

    hope i have explained it clear enough.

    as i said before in a post i don't think it needs merging into another array(might be wrong).

    //Create cart option
    $cart_option = '';
    if (isset($product_option_values)) {
    foreach ($product_option_titles as $product_option_title) {
    foreach ($product_option_values as $product_option_value) {
    $cart_option .= $product_option_title['option_title']." : ".$product_option_value['option_value']." ";
    }
    }
    }
    print_r($product_option_titles);
    print_r($product_option_values);
    echo $cart_option;
    

     

  6. this is the full code

     

    		//merge together both arrays
    		$new_cart_options =array_merge($product_option_titles,$product_option_values); //merged arrays
    		//loop combined arrays
    		foreach($new_cart_options as $options)
    		//setting output inside variable
    		$output= $options['option_title']." : ".$options['option_value']." ";
    		//output option title and value.
    		//making sure array is set and is not empty
    		if(isset($output) && !empty($output)){
    		print_r($output);
    		echo $output;
    		}else{ 
    		print "Array is not set or is empty";
    		}
    

     

    i am getting this still:

     

    Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

     

    Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

     

    Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    : Black : Black

     

    this is 239: $output= $options['option_title']." : ".$options['option_value']." ";

     

    doesent seem to like this: $options['option_title'] or $options['option_value'] array print out is same as other post.

    thanks for your help so far :)

  7. i am getting this:

     

    Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240

    Colours : Colours :

    Notice: Undefined index: option_value in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240

    Test : Test :

    Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 240

    : Black : Black

     

    this is 240: $output= $options['option_title']." : ".$options['option_value']." ";

  8. thanks for that, dident notice that, until you pointed it out, displaying fine now. i need to have a think how to get it displayed like i need it now title - value then if no value dont display the title

     

    this is the print array

     

    Array ( [option_title] => Colours ) Array ( [option_title] => Test ) Array ( [option_value] => Black ) Array ( [option_value] => Bacon )

     

    for the other arrays i did in the script i just do this to show certain results echo $options['option_title'];

    when i do this i get this: Notice: Undefined index: option_title in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    so how do i do this please?

  9. strange i changed to to the $key =

    and i get: Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    0 = Array/n

    Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    1 = Array/n

    Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    2 = Array/n

    Notice: Array to string conversion in C:\xampp\htdocs\jubileeleather\site\_class\store.php on line 239

    3 = Array/n

     

  10. i get this now:

    Notice: Undefined variable: cart_options on line 241

     

    Notice: Array to string conversion  on line 241

    Array

     

    heres the code

    		//Create cart option
    		$cart_option = '';
    
    		//checks if value is set and not empty no zero no float value 0.0 no NULL no FALSE
    		if (isset($product_option_values) && !empty($product_option_values)) {			
    
    		//merge together both arrays
    		$cart_options .= $product_option_titles+$product_option_values; 
    		//for testing purposes
    		print_r($cart_options);
    		}
    		echo $cart_option;
    

  11. thanks for getting back to me i did have a look at count but couldent figure out how to do it, so how do i add the stuff to get each loop to add them togeather like this:

     

    $cart_option .= $product_option_title['option_title']." : ".$product_option_value['option_value']." ";

     

     

     

  12. hi thanks again this is the print_r : Array ( [0] => Array ( [option_title] => Colours ) [1] => Array ( [option_title] => Test ) ) Array ( [0] => Array ( [option_value] => Black ) )

    and the echo: Colours : Black Test : Black

    heres the code now:

    		if (isset($product_option_values) && !empty($product_option_values)) {
    		//checks if value is set and not empty no zero no float value 0.0 no NULL no FALSE
    
    			foreach ($product_option_titles as $product_option_title) {
    			foreach ($product_option_values as $product_option_value) {				
    					$cart_option .= $product_option_title['option_title']." : ".$product_option_value['option_value']." ";
    				}
    			}
    		}
    		print_r($product_option_titles);
    		print_r($product_option_values);
    		echo $cart_option;
    

     

    thanks again

  13. hello all i am hoping someone can help me, i have to arrays some times the product_option_values has less or the same values as the product_option_titles when its less i want it to stop when its run out of values instead of continuing and duplicating the product_option_values until product_option_values has run out of values: see the $cart_option here,  Test : Black

    heres the code, really hope someone can help me i have been trying to figure it out all day.

    		//Create cart option
    		$cart_option = '';
    		if (isset($product_option_values)) {
    
    			foreach ($product_option_titles as $product_option_title) {
    			foreach ($product_option_values as $product_option_value) {				
    					$cart_option .= $product_option_title['option_title']." : ".$product_option_value['option_value']." ";
    				}
    			}
    		}
    		print_r($product_option_titles);
    		print_r($product_option_values);
    		echo $cart_option;
    

    heres the print_r's and the echo

     

    product_option_titles = Array ( [0] => Array ( [option_title] => Colours ) [1] => Array ( [option_title] => Test ) )

    product_option_values = Array ( [0] => Array ( [option_value] => Black ) )

    $cart_option = Colours : Black Test : Black

     

    thanks all.

  14. hello, hoping someone can help i am stuck on the last bit.

     

    		if (isset($product_option_values)) {
    		foreach ($store_variations_values as $store_variation_values) {
    		foreach ($product_option_values as $product_option_value) {
    			if($product_option_value == $store_variation_values['title']) {
    				$option_value_price += $store_variation_values['price'];
    			}
    			}	
    		}
    

     

    the code above doesent seem to be working i am getting no errors but its not adding it up the if($product_option_value == $store_variation_values['title']) is supposed to compare the option value and get the price for that item from the array, its working it out as 0 and should be 23 including the second value of the loop (1 is 22 and the other is 1) hoping someone could point out were i have gone wrong.

  15. hi, i this is how i am getting the information into the array

     

    		//get option prices
    		foreach($_POST['option_price'] as $key => $value){
    			if($value !=''){	
    				$product_option_prices[] = array("option_price" => $_POST['option_price']);
    			}
    		}
    

    and this is the price bit again

     

    this is the full print out: Array ( [option_value] => Array ( [1] => Black [2] => Bacon ) ) Array ( [0] => Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) [1] => Array ( [option_price] => Array ( [1] => 5.00 [2] => 0.00 ) ) ) 0

    		$option_price = 0;
    		if (isset($product_option_values)) {
    		foreach ($product_option_values as $product_option_value);
    		foreach ($product_option_prices as $product_option_price) {
    			//$option_price += $product_option_price['option_price'];
    		}
    		print_r($product_option_value);
    		print_r($product_option_prices);
    
    		}
    

    i thought this is how i call that array  $product_option_price['option_price'];?

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