Jump to content

BagoZonde

Members
  • Posts

    69
  • Joined

  • Last visited

Posts posted by BagoZonde

  1. Ok, one person asked me about this problem privately an hour ago, so after a few years, well, just two years, I can answer to my question :). Hope it helps other.

     

    This is very easy task, as .htaccess must be available in both directories. And the only difference between them is RewriteBase parameter:

     

    For main directory it will be:

    RewriteBase /
    

    And for test_directory it will be just:

    RewriteBase /test_directory
    

    So it's easy to keep whole project in separate directory nested in other one.

     

    I must say that it's funny how everything has changed in my development workflow since this post. For now I'm using VM with Vagrant and Ansible provisioning, Jenkins and so on. For this particular example I would rather expose my VM for somebody, or just create some staging server, etc. however sometimes it's quicker just to put some files somewhere so here is an answer. I hope everything's clear :).

  2. Hello!

     

    Is anybody know how to build Symfony 2 form (using Doctrine 2 and annotations) described as:

     

    1. I have KingEntity which contains "type", "settings" and "something_else" fields. "Settings" field will contain serialized data as it can differ depending on "type" selected.

    2. When type==1 I want get child-form (or something like that) QueenOne. And when type==2, I want get child-form QueenTwo, and so on. Each Queen* form contains different fields that's why I want to serialize it and put in "settings" field. I don't want to create new tables in database and create relations between them at all.

    3. So, if type==1 is selected, I want validate this form using QueenOne form. If validation success, I want to serialize that data from QueenOne and put into "settings" field of KingEntity, so KingEntity is keeped in database and it contains only "type", "settings" and "something_else" fields.

    4. I'm not interested with viewing this form, I need only backend part of logic for this kind of form.

     

    I hope I've explained it clearly. Any help will be appreciated.
  3. Well, finally I achieved my target few days ago.

     

    So, I've installed Virtual Box with Ubuntu, and I've used shared folder (/media/sf_htdocs) to share httdocs/ folder between Win8 and Ubuntu (@Virtual Box).

     

    Then I've mounted that folder with /home so I can access /home/[user]/public_html directly:

     

    sudo mount --bind /media/sf_htdocs/SomeProject/home /home

     

    so for now everything works like a charm. I can access site from the root. It was just Windows issue as that type of sites works well on *nix systems.

  4. Thank you for reply, kicken.

     

    I'm wonder how it works on live server (I'm not an author of this code).

     

    I can't change every place with __ROOTPATH__ (there are few of them), so how it works exactly?

     

    In other words, how to set my local server that same way as it was set on live serv?

    How to do it without touching anything in code? I don't get it.

  5. Hello everyone,

     

    I'm making some improvements to site I haven't created so please tell me how it exactly works as I have problems to configure it properly.

     

    I've downloaded all files and run localhost using XAMPP.

     

    Site should run when accessing /home/some_domain/public_html/index.php

     

    so I've created :

    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs/SomeProject/home/some_domain/public_html"
        ServerName some_project
        <Directory "C:/xampp/htdocs/SomeProject/home/some_domain/public_html">
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>

    That means, when I'm accessing http://some_project it runs index.php

     

    And that's ok.

     

    In index.php there's some include:
     

    include_once("includes/startup.php");

    So it includes relatively there: /home/some_domain/public_html/includes/startup.php

     

    And that's fine.

     

    However...

     

    In startup.php there's something like this:

    define("_ROOTPATH_","/home/some_domain/public_html/");
    

    and next line:
     

    include_once(_ROOTPATH_ ."includes/config.php");

    And that's my problem as index.php was executed from

     

    C:/xampp/htdocs/SomeProject/home/some_domain/public_html/

     

    so that include_once will behave this way:

     

    C:/xampp/htdocs/SomeProject/home/some_domain/public_html/home/some_domain/public_html/includes/config.php

     

    Of course such file is not available as it should direct to:

     

    C:/xampp/htdocs/SomeProject/home/some_domain/public_html/includes/config.php

    I'm not sure how it works on server and what I should do with my localhost to achieve that same environment.

     

    $_SERVER['DOCUMENT_ROOT'] for real site is: /home/some_domain/public_html

     

    Please help me to understand what I'm doing wrong.

     

  6. Ok, finally it's done. I was using some old extension for PDO written one year ago where some fetches were treated in other way. That means I was looking in wrong place but I've tested it with mysqli and that kind of SELECT was executed well.

     

    So, thanks to fetchAll(PDO::FETCH_GROUP) I'm getting two arrays (first for table1 and second one for table2) with data inside them. So this is the winner query for 100% clarity once again:

    (SELECT "table1" AS type, id, title, url FROM table1 ORDER BY id DESC LIMIT 0, 10)
    UNION
    (SELECT "table2" AS type, id, title, url FROM table2 ORDER BY id DESC LIMIT 0, 10)

    My dream-loop is happy now :].

     

    Thanks guys for help, especially for CrossMotion for hint with "fake" column name. That's a key!

     

    I'm not sure if this method is possible with mysqli as I want to get results in two arrays for each table, however PDO makes it possible easy way :].

    I hope it will help somebody else in future.

    Thanks!

  7. Thanks a lot, CrossMotion. I remember that I saw that attempt with additional field. So thanks to your hint, I do it that way as I have problems with LIMIT, but first that's a query that works well:

    SELECT "table1" AS type, id, title, url FROM table1
    UNION
    SELECT "table2" AS type, id, title, url FROM table2
    ORDER BY id DESC
    
    

    One thing about this query I'm not sure: I'm using PDO in PDO::FETCH_GROUP mode so first column determine grouping into array for "table1" and "table2" where results are nested.

     

    So no GROUP BY type was used there (and I'm not sure in regular mysql_ or mysqli_ GROUP BY would be needed). When I've added "GROUP BY type" of that query, it returns all results of "table1" and only one result of "table2"?! That's wrong because there should be more for sure! I was also trying with UNION ALL without luck.

     

    When trying to execute your query, I got error from PDO:

     

    SQLSTATE[HY000]: General error: 1221 Incorrect usage of UNION and ORDER BY

     

    It seems that selects must be in parentheses when ORDER BY used (that same for LIMIT), however when parantheses were added, it returns no results for this query:

    (SELECT "table1" AS type, id, title, url FROM table1 ORDER BY id DESC LIMIT 0, 10)
    UNION
    (SELECT "table2" AS type, id, title, url FROM table2 ORDER BY id DESC LIMIT 0, 10)

    My dream-loop is still sad ;].

  8. While iteratation of results I want to know from which table that records comes so I need some identification like GROUP. Two separate queries is what I got for now but I'm not spellbound and just looking for one query (it's for practice and exploring new things in MySQL you know :]). This is my dream-loop in general:

    foreach($result as $group){
       //Each column starts there, no matter if no records at all in first or second table
       print '<div class="column">';
       foreach($group as $tableName=>$record){
          //Let's rock with results for single table
          print '<div class="box box_' . $tableName . '">' . $record['title'] . '</div>';
       }
       print '</div>'; //End of column div
    }
    
  9. Hello,

     

    I have googled everywhere so I suppose it's impossible but it's better to ask you, MySQL/PHP Freak gurus :].

     

    I have two tables: table1 and table2. They represents content which are very different in structure, but both contains in common these fields: id, title, url and publish.

     

    I want to display list of contents: last 10 records from table1 to the left side and last 10 records from table2 to the right side.

     

    It's very simple with two queries. Just some:

    SELECT id, title, url FROM table1 WHERE publish=1 ORDER BY id DESC LIMIT 0, 10

    However I'm concerned if it's possible to achieve to have two selects in single query (some UNION maybe) and GROUP by SELECT (something like GROUP BY table comes to my mind). Maybe there's some trick with LEFT JOIN, etc. I'm just curious.

  10. Hello!

    I hope this is the right place to ask.

     

    I'm using Facebook PHP SDK (v.3.2.2) to share link on my Facebook's wall.

    Everything works fine, I can submit link and message.

     

    However there's a problem with image. Sometimes Facebook will find image I've expected but often he's selecting CAPTCHA image (which is located in HTML code at the bottom of page).

     

    So, how can I pick up right image for sharing on Facebook wall?

     

    When I'm sharing exactly that same links by hand on Facebook's wall - everything works fine, but with SDK it sucks very often.

     

    I was trying two things without luck:

     

    1. Post picture's filepath (see: PHP example below).

    2. By inserting:

    <meta property="og:image" content="http://www.absolutepath.to/image.jpg" />

    in head section.

     

    I can't find solution.

     

    This is some parts from my code as it's really not necessary to paste everything as all working well, it's just some image issue.

    Of course as post url I'm using /links to share instead of /feed to post. As I believe, this is the only way to create ability to share this post by other people on Facebook. When posting as /feed, no one can share this post.

    $configuration['facebook_scope']=>'publish_stream,offline_access,read_stream,manage_pages';
                    $post_url = '/'.$Field['FacebookPageID'].'/links'; //post as /links for share
    
                    $facebook = new Facebook($configuration['facebook_app']);
    
                    //the Posting Parameters
                    $PostData = array(
                        'message' => $Field['FacebookMessage'],
                        'link' => $Field['FacebookLink'],
                        'picture' => $Field['FacebookPicture'], //I'm not sure it's used for share, I think: it's not
                        'access_token' =>$OurAccessToken,
                    );
    $result = $facebook->api($post_url, 'post', $PostData);

    Please help me as I'm so close to make it real and I hope this post will help other people in future.

     

    P.S. I've checked url I want to share on https://developers.facebook.com/tools/debug and there everything looks fine with og:image

  11. Yeah, it will return only Notice in that particular situation but I'm not bother with that, in production state it's safe to hide error_reporting at all.

    For sure my example works properly, and your is more elegant.

  12. I don't get it a part with emailswitch(), what's that "field_?"???!

     

    Here's some piece solution:

        $to = array(
            'Pedicure Price Inquiry' => 'info@example.com',
            'Manicure Price Inquiry' => 'info@example.com',
            'Booking Time' => 'booking@example.com',
        );
    
        $send_to_email=$to[$_POST['category']];
    
        if (!$send_to_email){
            $send_to_email=$to['Booking Time']; //default e-mail
        }
    
    
  13. Hello,

     

    For testing purposes I need to run site from /test_directory/, however every element in index.php and other places uses absolute path, e.g.:

     

    /styles/style.css

    /images/some_image.jpg

     

    I was trying rewriting base to /test_directory/ but unfortunately instead of reading from:

     

    www.mysite.com/test_directory/styles/style.css

     

    PHP is reading from:

     

    www.mysite.com/styles/style.css

     

    where that file of course not exists.

     

    I'm not familiar with RewriteBase, however I think it should work that way if I want change base dir to subdirectory.

     

    So I need to change absolute path to every single file and every link.

     

    Here we go with my .htaccess:

     

     

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

     

    Any help will be appreciated.

     

  14. Hello Christian!

    Yes, I want words with punctuation. Subject of this thread is a short description of what I've written in first post as my target. I want to break if CR, space or tab. And I don't want to specify every sign as it's easier and safier to tell when to break. So I want to make "blacklist", not "whitelist".

     

    So, is there easy way to specify breaking string when CR, tab or space? I know how to break when space character ommit as I mentioned in my second post for this thread. But I have no idea how to include CR or tab too.

  15. Unfortunately not because commas and semicolon are missing, haven't you noticed that? I want to cut some range from this string into words (with semicolons, etc.), then implode back to string with space characters as I want to display something like that:

     

    ...minds every night to leave it early, but we make up our bodies every morning...

     

    For now use of preg_split() working like a charm for my purposes, but I can't separate words if CR is between.

    It's just some cut of text, so if I'm looking for word "early" I want to see some part of context, something like Google engine searcher can do.

  16. Thank you very much Christian, however it not meet my requirements but I'm on good track thanks to you. I need to break words if space, tab and CR as I mentioned in first post. Your code results with words divided for space character only. I get it with taking letters only, but I want to divide into array for space, tab and CR. So I need pattern which exclude exactly that. About commas, colons: it should be stick to word or digit as it is. Another example will tell you exactly what I'm looking for:

     

    The bed is a bundle of paradoxes: we go to it with reluctance,
    yet we quit it with regret;
    we make up our minds every night to leave it early,
    but we make up our bodies every morning to keep it late.
    
    Ogden Nash
    

     

     

    So I am writing a simple text search engine for easy purposes, so i.e. I was looking for "early" word. And now I want see results as a cutting, If word "early" was found on position 154 I want to take range -100 : +100. So I need only to cut part of this string to a words in array (with commas and other characters), then unset first and last word (as it would be not whole word) then implode with space character.

     

    Using \S I can explode words but I don't know how to explode CR (^\n and ^\r not works). I was trying with that one:

     

    preg_match_all('/([\S]+)/', $string, $words);

     

    And why results array is doubled?

     

    I found preg_split() so I think it could be better to focus on it in this case:

     

    $words = preg_split( "/(\s|\t)/", $string);

     

    However \n or \r or even \x0D or \x0D\x0A (chr(13).chr(10)) don't listen me in this OR statement. And I'm not sure about tab either.

     

    Thank you for interesting!

  17. I'm looking for regex pattern to substring whole words even from middle of text. It should divide for space, tab or CR.

     

    Here's an simple example:

     

    $string="The quick brown fox jumps over the lazy dog";
    print preg_replace($pattern, '', substr($string, 7, 15));
    

     

    So in this example for "ck brown fox ju" string I want to get:

     

    brown fox

     

    Of course I'm aware about substr from 0 or to last character of string, but that's easy, I need just regex pattern.

     

    It looks like a common case, but I was trying myself with \b, \w, \s and other stuff then searching for net deeper, however I haven't found any solution yet.

     

    I appreciate any help, I'm tired with regex for today. I've written this function using iteration method with substr(), but I'm not satisfied, I'm looking for something more elegant, so I'm concerned to learn more about regex.

     

    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.