Jump to content

laanes

Members
  • Posts

    70
  • Joined

  • Last visited

    Never

Posts posted by laanes

  1. I can't get my head around rewriting my websites URL's.

     

    I'd like to rewrite mywebsite.com/page.php to be accessed as:

     

    mywebsite.com/page or mywebsite.com/PAGE

     

    If there is no such page, then redirect to home page.

     

    So i've tried this:

     

    RewriteRule ^(\w+)\/?$ $1.php [NC] [L]

     

    RewriteCond %{REQUEST_FILENAME} !-f 

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule .* index.php

     

    Result:

     

    mywebsite.com/page_that_doesn't_exist - works as intended, takes me to index.php

     

    mywebsite.com/page works fine.

     

    mywebsite.com/PAGE gives me this - You don't have permission to access /C:/wamp/www/mywebsite.com/PAGE.php/ on this server.

     

    Why this kind of error and can i maybe force lowercase on PAGE ?

  2. Hi,

     

    I am adding "active_filter", "passive_filter" classes to links based on regex pattern coming from the URL:

    Line 46: https://github.com/laanes/product_filtering/blob/master/APF_URL.php

     

    The function gets called on line 89 in here: https://github.com/laanes/product_filtering/blob/master/boxes/advanced_product_filtering_box.inc.php

     

    You can see it in action here: http://www.swanseatimber.co.uk/shop/hafele/brand_281.html by clicking on a category on the left, under the heading "Filter Your Results".

     

    The clicked category gets a green background because of the added "active_filter" class. When you click again, it will get "passive_filter" class and the products are not filtered any more.

     

    The problem: When moving to other pages by using the pagination at the top of the product results, the class doesn't get added.

     

    Therefore, you can't remove the filter because function creating the href on line 72 in here: https://github.com/laanes/product_filtering/blob/master/APF_URL.php

     

    and the function clearing all filters on line 100 in here: https://github.com/laanes/product_filtering/blob/master/APF_URL.php both fail.

     

    What's interesting - when selecting a filter, moving to the next page, clicking in the browser url bar and hiting enter(hard reload i think?), the problem disappears and you can play with the filters again.

     

    I really hope you find a minute to look into it and help me.

     

  3. Can we see the actual code that builds this query?

     

    Thank you for your answer.

     

    The query was used twice inside of a loop, i removed the single quotes around the id value in the first query but they were still present in the second one, hence the error message - "syntax to use near '= '4879'' at line 1".

     

    I would now close this topic but can not find a way to do it.

     

    Kind regards,

    laanes

  4. Hello,

     

    Does anyone spot an error in the following SQL:

     

    "SELECT range_id, productId FROM range_idx WHERE productId = 4879 LIMIT 1" 

     

    I get:

     

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '4879'' at line 1

     

  5. Can anyone help me to figure out a pattern that matches all the underlined zn's ?

     

    mnzertainlyzn cznar availznable in zn finznish zn / zn, zn/zn zn umzn:)

     

    I tried this:

     

    '#\s?zn\s?#'

     

    This is close to what i expect but matches also the ones contained inside words which i don't want.

  6. Hmm, yes, i can see what you mean.

     

    But how would i get all the songs related to the album i searched for?

     

    Since the AI id is unique to every row, it means i can not link songs to albums like this? :

     

    "SELECT album, song FROM albums INNER JOIN songs ON albums.id = songs.id"

     

    I'd like to get all songs from the album "raccoon" for example.

     

     

     

     

     

     

  7. Sorry for not being clear enough.

     

    I would like the group the songs somehow for searching by album.

     

    So i have created table albums with id, album_id, album.

     

    Then i imported the albums from a textfile so that the id field got filled with auto incrementing numbers and albums field with album names.

     

    album_id didn't exist in the textfile so it got filled with 0's.

     

    I'd like for example song 1-9 to have album_id 1, song 10-19 to have album_id 2 etc.

     

    How could i accomplish this?

     

     

  8. I am using this rule:

     

    RewriteEngine on
    
    RewriteRule cat/(\w+)$ cat=$1

     

    Result:

     

    Both of these URLs work:

     

    http://localhost/urls/cat/mickey

    http://localhost/urls/urls.php?cat=mouse

     

    I thought the URL will be rewritten when there is a pattern match,  in the current case - cat/mickey should be rewritten to cat=mickey ?

     

    In fact, even http://localhost/urls/urls.php/cat/and/mouse/are/having/a/fight/over/bacon does not give an error, instead,  it is still displaying the content of http://localhost/urls/urls.php

     

    What am i missing?

  9. I would like to redirect everything in my root folder to home.php instead of index.php

     

    My htaccess file is located in the root folder and contains the following line:

     

    RewriteEngine on RewriteRule .* home.php 

  10. There is nothing specific that i am trying to do with it yet, just dropping in examples i can find on the web, like changing the default index page to something.html etc.

     

    If i put absolute nonsens into the .htaccess, i get:

     

    Internal Server Error

     

    The server encountered an internal error or misconfiguration and was unable to complete your request.

     

    Please contact the server administrator, admin@127.0.0.1 and inform them of the time the error occurred, and anything you might have done that may have caused the error.

     

    More information about this error may be available in the server error log.

     

  11. Hi,

     

    I started reading a tutorial on using .htaccess but got stuck at the very beginning.

     

    Nothing seems to work, no matter what i write into the file.

     

    I have placed it into my WAMP servers root folder and copied examples from the tutorial to test.

     

    I can see that it is enabled in the apache modules list and it is loaded via the httpd conf file.

     

    How could i get this thing to work?

     

     

  12. Also, I have tried to join another table with additional images in the query and it seems that i can not compare the fetched results against the folder because the list i get back contains also some images that excist in both, the images folder and the database.

     

    Would i have to compare every database table separately against the folder or can i join the tables and compare them together agains the folder?

  13. Hi dcro2

     

    Thank you for your reply!

     

    I will give it a try now and get back to you with the results.

     

    Thank you for helping me to understand about declaring $clean_fetch as an array first.

     

    Also thanks for pointing out that i should only go after the first array index not all of them.

     

    Talk to you soon,

    Thanks

  14. I wrote a piece of code that lists images that don't have a match in the database:

     

    $dir_path = '../images/productImages';
    $images = scandir($dir_path);
    
    $query = "SELECT image FROM Database_table ORDER BY name DESC";
    
    $results = mysql_query($query);
    
    $output  = "<h1>Missing Images</h1>";
    $output .= "<div class=\"missingImages\">";
    $output .= "<p>The following data was found in the Database_table.images field but not in /images/productImages:</p>";
    $output .= "<div class=\"missingImg\">";
    $output .= "<p class=\"fieldName\">Database_table.images:</p>";
    
    while ($fetch = mysql_fetch_array($results)) {
    
    $clean_fetch = str_replace("productImages/", "", $fetch);
    $diff = array_diff($clean_fetch, $images);
    foreach (array_unique($diff) as $key => $value) {
    
    	$output .= $value . "<br />";
    }
    }
    
    $output  .= "</div>";
    $output  .= "</div>";
    
    echo $output;

     

    Works.

     

    Now I would like to check whether there are any files in the folder that are not in the database table.

     

    I thought it would be as easy as swapping the array_diff parameters around but it's not.

     

    When i swap the parameters like so - array_diff($images, $clean_fetch) it gives me a list of ALMOST all the images in the image folder, which i don't understand.

     

    Why does it not give me only the images that are present in the folder but not in the database?

     

  15. Hello,

     

    I am trying to build a query that looks into the number of products that are currently in stock, and if that is lower than the quantity entered in the cart then notify me that someone bought more items than in stock.

     

    What kind of fields should i link to connect products and orders table?

     

    There are:

     

    product_id, product_code and order_id in the orders table.

     

    product_id, product_code and stock_level in the products table.

     

    With thanks,

    laanes

     

     

  16. Hi, i've got a question in my head:

     

    How could i improve the WHERE clause in this query? :

     

    $query = "SELECT cat_name FROM " . $table . " WHERE cat_id != 300 AND cat_id != 200 AND cat_id != 100";

     

    It works, but i can imagine when there will be more excluded categories, there will be a lot of AND's.

     

    Any way to make this query more decent?

     

    Kind regards,

    laanes

  17. Is this an effective way of accessing the $_GET and $_POST properties?

     

    I can see that the native $_GET function has been looped through so that $varName would be for example "username" and $value would be "Jeremy". Then they are both stored into an array called $getVars?

     

    Is this the best way of doing it, if not then why?

     

    foreach($_GET as $varName=>$value)

     

    $getVars[$varName]=trim(clean($value, 100));

     

    foreach($_POST as $varName=>$value)

     

    $postVars[$varName]=trim(clean($value, 100));[/code]

     

    Kind regards,

    laanes

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