Jump to content

imgrooot

Members
  • Posts

    383
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by imgrooot

  1. Use a loop and an array to store the results.

     

    $pages = [];
    for ($pageNumber=1; $pageNumber <= 100; $pageNumber++){
        $pages[] = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=' . $pageNumber . '">' . $pageNumber . '</a>';
    }
    

     

    That's great.  Now my next question is, how do I echo all 100 of those a href links outside the for loop?

  2. Here's a line.  I want to add 100 more of same lines and increment the page numbers as shown below.  I know I can just manually add 100 lines but Is there a way to do this with PHP that would make it easy? Or is this more of a javascript thing?

    
    // original
    $page1 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=1">1</a>';   
    
    
    // new
    $page1 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=1">1</a>';
    $page2 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=2">2</a>';   
    $page3 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=3">3</a>';  
    $page4 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=4">4</a>';  
    $page5 = '<a href="?type='. $type_id .'&name='. $get_type_3_name_slug .'&page=5">5</a>';   
    ...etc                                                                                                                                       
    
  3. I am finding that if I have "0"(zero) value in form select option, it won't select this option or submit data.  If I change this value to any other number to text, it will work.  Is there a way to fix this?  I have to have an option where I am able to choose to submit "0" value to the database table.

    <option value="0" <?php if(empty($_POST['special'])) {} else { if($_POST['special'] == 0) { echo 'selected'; } } ?> >None</option>
    
  4. Here's what I am trying to do.

     

    Retrieve "title" and "slug title" from all the rows in a table.  Update them with new "title", "slug title" and "brand name". 

     

    Here's my query. It updates the table with the brand names for each row.  But for some reason, it removes the title and slug title from all the rows in the table.  Is there a reason why it's doing that?

    function getIt($var) {
        $pos = strpos($var, ' - ');
        echo(substr($var, $pos+3)."\n");
    }
    
    if(isset($_POST['submit'])) {
    
      $get_record = $db->prepare("SELECT * FROM items");
      $get_record->execute();
      $result_record = $get_record->fetchAll(PDO::FETCH_ASSOC);
      if(count($result_record) > 0){
        foreach($result_record as $row) {
    
          $get_item_id		=	intval($row['item_id']);
          $get_item_title		=	trim($row['item_title']);
          $get_item_title_slug	=	trim($row['item_title_slug']);
    
          $new_title = getIt($get_item_title);
          $new_title_slug = Output::createSlug($new_title);
          $brand_name = substr($get_item_title, 0, strpos($get_item_title, ' - '));
        
    
          $update_record = $db->prepare("UPDATE items SET brand_name = :brand_name, item_title = :item_title, item_title_slug = :item_title_slug WHERE item_id = :item_id");
          $update_record->bindParam(':item_id', $get_item_id);
          $update_record->bindParam(':brand_name', $brand_name);
          $update_record->bindParam(':item_title', $new_title);
          $update_record->bindParam(':item_title_slug', $new_title_slug);
          if(!$update_record->execute()) {
    
            $errors[] = 'There was a problem updating the item.';
    
          }
          
        }
      } else {
    
        $errors[] = 'No item found.';
      }
    
    }
    
  5. Good job getting the second step working.

     

    Understand that it will be several hundred rows, but are you doing so to fix the table?  Your database should have a table for the company and a table for the product, and the application should create the combined string.  Your database should not directly be saving the combined string.

     

    Yes I am doing it so that in the future I can I filter out products by "Brand" name.  Currently the brand name is directly in the title. I can still have it in the title when I output the variables but in the database, it would be better to have it in an individual column.

  6. Are you doing this just once to fix a badly designed table?  If not, you shouldn't be doing this.

     

    To do the next step, just do it the same way.  Figure out where your deliminator position is using strpos(), and use substr() to return the correct string.

     

    I think I have it working for the 2nd step. 

    $variable_1 = 'Lulu-free - Swimsuit swimwear red';
    $variable_2 = 'Pap & Jones - Bard Mini Dress';
    
    $str1 = substr($variable_1, 0, strpos($variable_1, ' - '));
    // results: Lulu-free
    
    
    $str2 = substr($variable_2, 0, strpos($variable_2, ' - '));
    // results: Pap & Jones
    

    No unfortunately it is not once but several hundred rows.

  7.  

    Maybe?

    <?php
    
    function getIt($var)
    {
        $pos = strpos($var, ' - ');
        echo(substr($var, $pos+3)."\n");
    }
    $variable_1 = 'Lulu-free - Swimsuit swimwear red';
    $variable_2 = 'Pap & Jones - Bard Mini Dress';
    getIt($variable_1);
    getIt($variable_2);

     

     

    That works perfectly. 

     

    One more thing.  Basically I have a long list of items in MySQL database with the title in the format I specified above. Basically what I am trying to do is do 2 things.

     

    1. Remove everything before the " - " to create a new title. This works thanks to you.

     

    2. The string that is removed before the " - ", I want to add it to a new table column. 

    Now my next question is, how do I get these strings(Lulu-free, Pap & Jones) as a variable? 

  8. Below I have "Input" where it shows the original string.  Basically I want to remove everything before " - ".  I would like to know how can I get the "Output" results using PHP? 

    Input
    $variable_1 = Lulu-free - Swimsuit swimwear red
    $variable_2 = Pap & Jones - Bard Mini Dress
    
    Output
    $variable_1 = Swimsuit swimwear red
    $Variable_2 = Bard Mini Dress
    
  9. This makes no sense. You're now assuming an alphabetical type followed by a numerical name, but your link above has the exact opposite (a numerical type and an alphabetical name).

     

    Again: You have it backwards. You tell us your the URLs should look like. And then we can tell you how to implement them. Guessing from your example, it seems you want this:

    /belts/45
    

    So first the category, then the numerical type. Correct?

     

    Well yes like that, although belts can come after the 45.  Like this.

    shop/45/belts
    
  10. Designing the URLs is your job. “Pretty URLs” are just an abstract concept for URLs that are optimized for readability. How exactly your URLs should look like is something only you know. A good guideline is Cool URIs don't change from Tim Berners-Lee himself.

     

    I've been pulling my hair trying to figure this out and so far unsuccessful.  It would be very helpful if someone knowledgeable about this can help me out.  Every professional site I see out there has pretty urls, as oppose to what I have above.  Even phpfreaks site has pretty urls.  How would I go on about doing that based on the link I provided above?  So far all I got is this. How would I change the above link to match this?

    RewriteRule ^([a-z]+)\/([0-9]+)\/?$ shop.php?type=$1&name=$2 [NC]
    
  11. I have a Mysql table where I store prices of a product.  I have the values in "varchar" format because I needed to include "decimals" in the prices(for eg. 15.30) and "int" doesn't allow that.

    Having done that, when ever I filter the products by prices in Ascending or Descending order, they don't show up in proper order. It seems like the decimal in the prices is messing up the order.

     

    Is there a way to fix this so that the php query can filter the prices in proper order despite the decimals?

     

    Here's the eg of the query.

    $get_records = $db->prepare("SELECT * FROM records ORDER BY records.price DESC");
    
  12.  

    I have it working now. And yes it is a CSS problem. Here's the css code. Note that "Overflow-y" will only work if the position is defined.  Without the "position:fixed", my nav-mobile dropdown didn't open when I clicked toggle.

    .nav-mobile {
      display: none;
      *zoom: 1;
      position: fixed;
      width: 100%;
    
      overflow-y: scroll;
      -ms-overflow-y: scroll;
      -webkit-overflow-scrolling: touch; // mobile safari
    }
    

     

    One small edit. Add the height: 100%. It'll fix any y scrolling issue.  Here's the updated code.

    .nav-mobile {
      display: none;
      height: 100%;
      *zoom: 1;
      position: fixed;
      width: 100%;
    
      overflow-y: scroll;
      -ms-overflow-y: scroll;
      -webkit-overflow-scrolling: touch; // mobile safari
    }
    
  13. Care to provide a link to the a working application.  Otherwise, we can only take shots in the dark.  At least provide a screenshot and/or CSS, because this is probably more of a CSS problem than a JS problem.

     

    I have it working now. And yes it is a CSS problem. Here's the css code. Note that "Overflow-y" will only work if the position is defined.  Without the "position:fixed", my nav-mobile dropdown didn't open when I clicked toggle.

    .nav-mobile {
      display: none;
      *zoom: 1;
      position: fixed;
      width: 100%;
    
      overflow-y: scroll;
      -ms-overflow-y: scroll;
      -webkit-overflow-scrolling: touch; // mobile safari
    }
    
  14. Right now I have a mobile dropdown that works fine.  The only issue I have is that when viewing it on my smartphone, the dropdown gets cut off at the bottom and I am unable to scroll it down to rest of it.  Is there a way to fix it so that It's scrollable?

     

    Here's my js code of the dropdown.

    $(document).ready(function() {
    	$(".nav-mobile li a").each(function() {
    		if ($(this).next().length > 0) {
    			$(this).addClass("parent-arrow");
    		}
    	})
    
    	$(".toggle-mobile-menu").click(function(e) {
    		e.preventDefault();
    		$(this).toggleClass("active-mobile");
    		$(".nav-mobile").toggle();
    	});
    
    	adjustMenu();
    });
    
    $(window).bind('resize orientationchange', function() {
    	ww = document.body.clientWidth;
    	adjustMenu();
    });
    
    var adjustMenu = function() {
    	var ww = document.body.clientWidth;
    	if (ww <= 850) {
    		$(".toggle-mobile-menu").css("display", "block");
    		if (!$(".toggle-mobile-menu").hasClass("active-mobile")) {
    			$(".nav-mobile").hide();
    		} else {
    			$(".nav-mobile").show();
    		}
    		$(".nav-mobile li").unbind('mouseenter mouseleave');
    		$(".nav-mobile li a.parent-arrow").unbind('click').bind('click', function(e) {
    			// must be attached to anchor element to prevent bubbling
    			e.preventDefault();
    			$(this).parent("li").toggleClass("hover");
    		});
    	}
    	else if (ww > 850) {
    		$(".toggle-mobile-menu").css("display", "none");
    		$(".nav-mobile").hide();
    		$(".nav-mobile li").removeClass("hover");
    		$(".nav-mobile li a").unbind('click');
    		$(".nav-mobile li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
    		 	// must be attached to li so that mouseleave is not triggered when hover over submenu
    		 	$(this).toggleClass('hover');
    		});
    	}
    }
    
  15. So you're talking about a foreign key used to join the two tables?

     

    Then the ID is better, because it's stable and efficient. Names change, which means the database has to keep the tables synchronized. And names are long, which means it's relatively expensive to compare them.

     

    Numeric IDs, on the other hand, are unlikely to ever change, and they have a fixed length.

     

    Got ya. Thanks.

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