Jump to content

djones

Members
  • Posts

    74
  • Joined

  • Last visited

    Never

Posts posted by djones

  1. I need to add these lines to my .htaccess file via PHP

     

    RewriteCond %{REQUEST_URI} checkout 
    RewriteRule ^(.*)$ https://myurl.com/checkout/$1 [R,L]

     

    RIGHT after this line:

    RewriteBase /

     

    AND before this line:

    RewriteCond %{REQUEST_FILENAME} !-f

     

    This is how the current file looks w/o the new line addition:

     

    RewriteEngine On
    
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php [L,QSA]

     

    It needs to look like this when the new lines are added(extra line breaks not necessary):

     

    RewriteBase /
    
    RewriteCond %{REQUEST_URI} checkout 
    RewriteRule ^(.*)$ https://myurl.com/checkout/$1 [R,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php [L,QSA]

     

    The line numbers may not match up, so I cannot use the line number.

  2. I'm trying to insert unique data based on 2 fields. The product_id and the value_id combined should be unique. I'm not sure how to do this.

    I have:

    ID(primary key) -- not shown below

    PRODUCT_ID(unique key)

    VALUE_ID(unique key)

    VARIATION_ID

     

    I need product_id and value_id to be unique together. When I insert this data it only insert one row and I'm assuming it's because It's just looking at each unique fields by itself thus stopping at the next '37' insert. For example 37 and 11 should not insert twice, 37 and 3 ...etc

     

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '11', '4')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '3', '2')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '10', '4')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '3', '2')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '9', '4')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '11', '4')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '10', '4')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

    INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '9', '4')

  3. A friend was able to help. I'm posting it here for others to see.

     

    
    // Put each variation set into an array
    // i.e $set[0] is your Sizes, $set[1] is your Colors
    /*
    
    Sizes
    
    array(4) {
      [0]=>
      string(2) "SM"
      [1]=>
      string(3) "MED"
      [2]=>
      string(2) "LG"
      [3]=>
      string(3) "XXL"
    }
    
    Colors
    
    array(3) {
      [0]=>
      string(4) "Blue"
      [1]=>
      string(5) "Green"
      [2]=>
      string(3) "Red"
    }
    
    */
    
    $options = array();
    $current_index_path = array();
    $variations = -1;
    
    function variation_matrix($variations, $current_index_path, &$options, &$set) {
    
    	$variations++;
    
    	if ( $variations == count($set) - 1 ) { //you are at the last group
    
    		for ( $i = 0; $i < count($set[$variations]); $i++ ) {
    
    			$option_string = "";
    
    			for ( $j = 0; $j < count($current_index_path); $j++) {
    
    			    $option_string .= $set[$j][$current_index_path[$j]]. " : ";
    
    			}
    
    			$option_string .= $set[$variations][$i];
    			$options[] = $option_string;
    
    			}
    
    		} else {
    
    			for ( $i = 0; $i < count($set[$variations]); $i++ ) {
    				$cip_copy = $current_index_path;
    				$cip_copy[] = $i; //append index from this variation
    				variation_matrix($variations, $cip_copy, &$options, &$set); //dig deeper
    			}
    
    		}
    
    	}
    
    variation_matrix($variations, $current_index_path, &$options, &$set);
    
    /* Output
    array(12) {
      [0]=>
      string(9) "SM : Blue"
      [1]=>
      string(10) "SM : Green"
      [2]=>
      string( "SM : Red"
      [3]=>
      string(10) "MED : Blue"
      [4]=>
      string(11) "MED : Green"
      [5]=>
      string(9) "MED : Red"
      [6]=>
      string(9) "LG : Blue"
      [7]=>
      string(10) "LG : Green"
      [8]=>
      string( "LG : Red"
      [9]=>
      string(10) "XXL : Blue"
      [10]=>
      string(11) "XXL : Green"
      [11]=>
      string(9) "XXL : Red"
    }
    
    */
    
    

  4. I'm struggling with how to dynamically loop through a product's list of options. Let's day I have the variations, Size(variation_id = 2) and Color(variation_id = 4) assigned to product A. Which produces these arrays:

     

    // Sizes
    array(4) {
      [0]=>
      string(2) "SM"
      [1]=>
      string(3) "MED"
      [2]=>
      string(2) "LG"
      [3]=>
      string(3) "XXL"
    }
    
    // Colors
    array(3) {
      [0]=>
      string(4) "Blue"
      [1]=>
      string(5) "Green"
      [2]=>
      string(3) "Red"
    }
    

     

    I know I can hard code the loop, but that will not work if I add another variation. How can I build the loop to work with any amount of variations?

     

    // Get the variations from the product_id A
    // $sql = "SELECT variation_id FROM product_variations WHERE product_id = 'A'
    / ...
    // I can query for the variations and loop through to get the variation values
    // ...
    // $set1 is the Sizes array from mysql query
    // $set2 is the Colors array from mysql query
    $count1 = count($set1);
    $count2 = count($set2);
    
    for ($a=0; $a < $count1; $a++){
    
        for ($b=0; $b < $count2; $b++){
    
    $options = $set1[$a].' : '.$set2[$b];
    echo $options.'<br />';
    
        }
    
    }
    
    // Output
    /*
    SM : Blue
    SM : Green
    SM : Red
    MED : Blue
    MED : Green
    MED : Red
    LG : Blue
    LG : Green
    LG : Red
    XXL : Blue
    XXL : Green
    XXL : Red
    */
    

  5. Cannot get my brain around what strtotime it looking for. I need to echo the same day for each month for the next 12 months.

    This is not working.

     

    for($i=0; $i<=12; $i++){
    
    $date = date("Y-m-d", strtotime('17 +'.$i.' months'));
    
    echo $date.'<br />';
    }
    

  6. I've read that article before and cannot find a way to create a dynamic menu from it.

    This part of the article where it shows the concat()...

     

    SELECT CONCAT( REPEAT( ' ', (COUNT(parent.name) - 1) ), node.name) AS name
    FROM nested_category AS node,
    nested_category AS parent
    WHERE node.lft BETWEEN parent.lft AND parent.rgt
    GROUP BY node.name
    ORDER BY node.lft;
    

     

    ... illustrates the idea but to create a valid <ul> list is different. You have to nest the tags correctly, and I cannot figure that part out.

  7. Hi,

     

    First I need to change some of the data. I need to change those items with a parent_page_id of 1 to have a parent_page_id of 0. I hope this is acceptable. This is because we want these items to be top level ones and not the children of page_id 1.

    You need to use a recursive function to build the array:

    <?php 
    function build_menu($tmp, $parent_page_id, $page_menu_title, $page_id){
    if($parent_page_id==0){
    	//if it's a top level item we can just add it straight to the array.
    	//NB the result set must be ordered so the items with parent_page_id=0 must all come first.
    	$tmp[$page_id]=array('name'=>$page_menu_title);
    }
    else{
    
    	if(array_key_exists($parent_page_id, $tmp)){
    		//print 'parent('.$parent_page_id.') found at current level... adding item('.$page_menu_title.')<br>';
    		//If the parent is in the current level of the menu array, we can add the sub item...
    		$tmp[$parent_page_id][$page_id]=array('name'=>$page_menu_title);
    	}
    	else{
    		//print 'parent('.$parent_page_id.') not found at current level, looping...<br>';
    		//... otherwise we need to do a recursive loop through the menu array, so we will eventually find the parent no matter where it lives in the menu. (as we've ordered the results we're looping over, the parent will have always been created by this stage therefore eventually the if statement above will hold true)
    		foreach($tmp as $id => $next_level){
    			if(is_array($next_level)){
    				$tmp[$id]=build_menu($next_level, $parent_page_id, $page_menu_title, $page_id);
    			}
    		}
    	}
    }
    return $tmp;
    }
    ?>

     

    and you'd call it whilst looping over the result of the database query like this:

     

    <?php
    $menu=array();
    while($row = mysql_fetch_array($result)){
    $menu = build_menu($menu, $row['parent_page_id'], $row['page_menu_title'], $row['page_id']);
    }
    ?>

     

     

    In order to produce a html menu from this array you'll need another recursive function like so:

    <?php
    function build_menu($menu){
    $m='<ul>'."\r\n";
    foreach($menu as $id=>$data){
    	if(is_array($data)){
    		$m.='<li>'.$data['name'];
    		if(count($data)>1){
    			$m.=build_menu($data);
    		}
    		$m.='</li>'."\r\n";
    	}
    }
    $m.='</ul>'."\r\n";
    
    return $m;
    }
    
    ?>

     

    This will produce html like this:

    <ul>

        <li>Home</li>

        <li>Services

            <ul>

                <li>Window Cleaning</li>

                <li>Sweeping</li>

                <li>Car Wash

                    <ul>

                        <li>Wash only</li>

                        <li>Wash and wax</li>

                        <li>Wash, wax and vac</li>

                    </ul>

                </li>

                <li>Gardening</li>

            </ul>

        </li>

        <li>About Us</li>

        <li>Contact Us</li>

    </ul>

     

    Hope this helps,

    Joe

     

    This works perfect for me, but I have another row with a page sort id. How do I sort the array with the page sort id?

     

    $page_sort_id = $row['page_sort_id'];

  8. I can't seem to get my mind on this correctly. I need $page_content to go through each function, but It seems to either replace itself or duplicate itself.

     

    $filter is an array of function names
    
    $count = count($filter);
    
    if($count > 0){
    
    foreach($filter as &$func){
    
    	$page_content = $func($content); // where the function returns the content. see sample functions below
                    // $page_content .= $func($content); // not working either
    
    }
    
    }
    
    function replace_text($content){
    
    $content = str_ireplace('test', 'WORKING', $content);
    
    return $content;
    
    }
    
    function replace_text_again($content){
    
    $content = str_ireplace('page', 'THIS AN EXAMPLE', $content);
    
    return $content;
    
    }
    
    
    echo $page_content;
    

  9. I'm inserting/displaying date/time based on this flow:

     

    INPUT

    User input -> convert to server time -> insert date/time into table

     

    OUTPUT

    select date/time from table -> convert to user's date/time - > display date/time to user

     

    The above part works great until I need the events for a full day.

     

    My problem is when I need to get events based on a day, month, year and not the time. I need to get the full days events.

     

    If a user picks Jan, 28th 2010 at 00:00:00 time it will insert into the table for the 27th 23:00:00 (server time).

     

    When I query the database or events on the 28th I do not have the time. Only the month,day,year. So  its looking for events on the 28th when it was inserted as 27(server time). How can I get around this?

     

  10. I live in EST US. My server is in Central US. Which is the better way to display the date/time for my time zone. Should I convert it going into the database via INSERT, or convert it during the SELECT query? I will eventually have users that will set their own time zones.

     

    Any insight would be greatly appreciated.

  11. The reason why I do not want to pass it in the function is because the function will be a configuration function for a user, I was trying to make is as clean as possible. I did not want the user to have to worry about what the other variable was for.

     

    // easier for user
    function nav($id){}
    
    // Do not wish todo
    function nav ($id, $oClass){}
    

     

    With that, is a global safe? Or should I re-initialize the class again in the function?

  12. What is the best way to accomplish this? I need to reuse a class inside a function. Is it ok on performance to intialize the class again in the function? See below.

     

    $oClass = new cClass();
    
    // ... Use class for tasks ...
    
    // Use class in function without passing $oClass
    // Want to do this without having to initialize the class again. OR is this OK?
    function nav($id){
      // Would not like to initialize class again.
      // $oClass = new cClass()
       // do stuff with $oClass
    
    }
    
    // I do not want to do this
    function nav($id, $oClass)[
    
       // Do stuff with $oClass
    }
    
    

  13. Trying to parse some XML using simplexml_load_string. When I do a var_dump of the XML I get

     

    object(SimpleXMLElement)#3 (2) {
      ["AuthResponse"]=>
      object(SimpleXMLElement)#4 ( {
        ["ReturnCode"]=>
        string(2) "40"
        ["Status"]=>
        string(1) "F"
        ["ActualStatus"]=>
        object(SimpleXMLElement)#6 (0) {
        }
        ["AuthMsg"]=>
        string(57) "The Quantity field must be greater than 0 - Line item = 1"
        ["AuthCode"]=>
        object(SimpleXMLElement)#7 (0) {
        }
        ["CCType"]=>
        string(4) "VISA"
        ["AVS"]=>
        object(SimpleXMLElement)#8 (0) {
        }
        ["PCode"]=>
        object(SimpleXMLElement)#9 (0) {
        }
      }
      ["SubmittedData"]=>
      object(SimpleXMLElement)#5 (7) {
        ["TranNum"]=>
        string(7) "1008854"
        ["TotalAmt"]=>
        string(4) "7070"
        ["DbCr"]=>
        string(1) "D"
        ["AuthType"]=>
        string(1) "A"
        ["OrigTran"]=>
        object(SimpleXMLElement)#10 (0) {
        }
        ["U1"]=>
        object(SimpleXMLElement)#11 (0) {
        }
        ["U2"]=>
        object(SimpleXMLElement)#12 (0) {
        }
      }
    }
    
    

     

    Using this is not returning anything.

     

    $return_code = $xml->authresponse->returncode; 

     

  14. For some reason the nested query is stopping the parent from completing. What am I over looking?

    Of course this is not the actual query but an example that fails too.

     

    public function list_stuff(){
    
    	$sql = "SELECT id FROM project";
    
    	$this->query($sql);
    
    	while ($row = $this->rs->fetch_assoc()) {
    
    
    		echo $row['id'].'<br />';
    		echo $this->pull_more_stuff($row['id']).'<br />';
    
    	}
    
    
    }
    
    public function pull_more_stuff($id){
    
    	$sql = "SELECT project_name FROM project WHERE id = '".$id."'";
    	$this->query($sql);
    
    	$row = $this->rs->fetch_row();
    
    	return $row[0];	
    
    
    }
    

     

    If I comment out

    echo $this->pull_more_stuff($row['id']).'<br />';

     

    the parent query will complete and I will get the results (project ids):

    1

    2

    3

     

    When I leave that line in I get:

    1

    Project Name

  15. I'm forwarding subdomains to a certain page. The problem is it won't give me access to other pages outside that. For example if I try to go to login.php it keeps sending me to company.php. This is what I have so far

     

    Options +FollowSymLinks
    
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
    RewriteRule .* http://www.%1%{REQUEST_URI} [R=301]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
    RewriteRule .* - [L] 
    
    RewriteCond %{HTTP_HOST} ^(^.*)\.mydomain.com
    RewriteRule (.*)  company.php?company=%1 [QSA,L] 
    

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