Jump to content

BloodyMind

Members
  • Posts

    98
  • Joined

  • Last visited

    Never

Posts posted by BloodyMind

  1. I would recommend storing only the product ID, and retrieve the price from the database

    I assume every product has an ID and the order page, which set this product to purchase

    The order page has to set the purchased product ID with the new ID not the existing one, in case the user had returned and picked another product

     

  2. you cannot include a URL

    you should include a file not a url, for instance /var/www/a-file.php

    you can include that file, but force the $_GET with the keys you want.

    and you cannot use return without a function

     

    if you want to use job-details both way, then force the $_GET vars

    $_GET['job']='jobname';
    $_GET['city']='thecity';
    include_once 'php/job-details.php';
    

    but if you don;t need to execute job-details.php directly from the browser, then just set the job and city vars as normal variables not $_GET and read them in the other file.

     

    I'd recommed that you read more about php

     

    I hope my reply was helpful

     

    Goodluck

     

     

  3. Here is the final code so everyone who come accross this problem benefits from it:

    $str = "
    
    <html>
    <head><title>Testing RegEx</title>
    <style type='text/css'>
    .p{
    font-color:red;
    }
    </style>
    </head>
    <body>
    <p> Regex is <b> awesome </b>.peep, creep</p>
    <p> Another paragraph
    <ul>
    <li><a href='#' ><img alt='dzzd' /></a></li>
    <li><a href='#' ><img alt='dzzd' class='omar' /></a></li>
    <li><a href='#' ><img alt='dzzd' class='omarr' /></a></li>
    </ul>
    </p>
    <b>aweful</b>
    </body>
    </html>
    ";
    // match the ul that has li>a>img
    $exp="#<ul>.*?(<li>(<a(.*?[^>])>)(?>(.*?)</li>))+.*?</ul>#Uis";
    $replaced = preg_replace_callback($exp,adjustImages,$str);
    // remove the list: ul li
    function removeList($groups){
    $groups[0] = str_replace(array('<li>','</li>','<ul>','</ul>'),'',$groups[0]);
    return $groups[0];
    }
    // add the desired class to the img tags
    function addClass($groups){
    return preg_replace('/(<img\b[^>]*) /Uis', '$1 class="thumb" ', $groups[0]);
    }
    // remove the existing classes
    function removeClasses($groups){
    return preg_replace('/(<img\b[^>]*) class=\'[^\']+\'([^>]*>)/Uis', '$1$2', $groups[0]);
    }
    /**
    * Remove any classes from img tags, 
    * add the desired class to the images
    * remove the lists
    */
    function adjustImages($groups){
    
    $groups[0] = addClass($groups);
    $groups[0] = removeClasses($groups);
    $groups[0] = removeList($groups);
    return $groups[0];	
    }
    

  4. I'm building a wordpress plugin, so I want the user to put an image list, and I later put on a jquery plugin to expect this

    <ul>

    <li><a><img attr1='val1' class="a"></a></li>

    <li><a><img attr1='val1' ></a></li>

    </ul>

    and matches this structure, if it matched, I would replace the class attribute if it exists with myclassname and if it doesn't it adds it to the img tag

     

    consider this input:

    <html>
    <head><title>Testing RegEx</title>
    <style type='text/css'>
    .p{
    font-color:red;
    }
    </style>
    </head>
    <body>
    <p> Regex is <b> awesome </b>.peep, creep</p>
    <p> Another paragraph
    <ul>
    <li><a href='#' >dzzd</a></li>
    <li><a href='#' ><img alt='dzzd' /></a></li>
    <li><a href='#' ><img alt='dzzd' class='omar' /></a></li>
    <li><a href='#' ><img alt='dzzd' class='omarr' /></a></li>
    </ul>
    </p>
    <b>aweful</b>
    </body>
    </html>
    

     

    What I have done so far is the following

    $exp="#<ul>.*?(<li>(<a(.*?[^>])>)(?>(.*?)</li>))+.*?</ul>#Uis";
    $replaced = preg_replace_callback($exp,addClass,$str);
    function addClass($groups){
    $patt = '#<img(.*)(?!class)(.*)/>#Uis';
    return preg_replace($patt,'<img $2 $3 class="myclassname"',$groups[0]);
    }
    

    I'm trying to match anything in the tag that is not class='anything' then match class='anything' then match anything after class='anything'

     

    but I can't get it to work,

     

    I've read that the negative look-ahead assertions will help, but I'm trying to learn how to use it

    so any help will be really appreciated :)

  5. I've got the same problem but my difference that, it sets the script path correcty, but I don't want it to try to load it from the controller path

     

    e.g. my case:

    the view: zf/news.phtml

    controller name: artist

     

    $this->view->setScriptPath(realpath(APPLICATION_PATH . '/..'));

    $this->render('news');

     

    I get this error:

    script 'artist/news.phtml' not found in path (<MY ROOT PATH>)

     

    so it tries to put in the controller's folder, and I want to remove it

     

    any ideas ?

  6. If I were you I would have set the session name outside and assign it to a class property

    through the constructor or directly (after instantiation)

     

    if you're not going to use the rest of the class so often and will use this method alot, just make it a static method for quicker access and less code

     

    try not to think too much of OOP in design in the very beginning, you'll learn more by practice.

     

    It's vague in the beginning like the abstract class concept didn't make any sense to me in the beginning, after that when I needed it. I understood.

  7. It can be search engine friendly by using apache mod_rewrite but this is another topic, you'll have to search for some tutorials

     

    .. you can do this in the very beginning in your script but I prefer doing it in a separate configuration file

     

    <?php
    
    // server base directory
    define('BASE_DIR','public_html/');
    
    // local base directory
    define('BASE_DIR','www/hosting/');
    
    require(BASE_DIR . 'include/header.php')
    
    ?>
    

     

    comment any of the defined statements u don't use

    e.g. on the server comment the define statement of the local directory

  8. I would recommend using constants as base directories and its always better to use absolute paths than relative paths and its faster

     

    It's also better to include files from an index page, its much easier to include since u don't have to calculate where are u now in the application

     

    so if you did:

    index.php

    <?php
    require('include/header.php');
    require('cart/h/h_shop.php');
    ?>
    

     

    and manage it with get variables

    for instance you want the index.php to load the h_shop script

    you can call do this:

    <?php
    require('include/header.php');
    if($_GET['go'] == 'shop'){
    require('cart/h/h_shop.php');
    }
    ?>
    

     

    and call it index.php?go=shop

     

    you will need to use a switch statement if you got many pages

     

    hope that helped :)

  9. I've got an open source LMS that contains TinyMCE as an editor

     

    I want to embed FLV in tinyMCE through the media plugin

     

    TinyMCE has no documentation at all, their wiki is not useful at all

     

    does anyone knows how to modify the embedded code through the media plugin in tinyMCE ? or have a solution ?

  10. I have this function working on my localhost: running perfectly

    CREATE DEFINER=`MYUSERNAME`@`localhost` FUNCTION `member_networth`(`member_id` double) RETURNS double
    BEGIN
    DECLARE networth DOUBLE;
    SELECT total_net_worth INTO networth FROM member_balance mb WHERE mb.member_id=member_id ORDER BY balance_date DESC LIMIT 1 ;
    RETURN networth;
    END
    

     

    When I tried to import it on the server or write this SQL into PMA on the server

    I doesn't work giving me the following error:

    SQL query:
    
    CREATE DEFINER = `MYUSERNAME`@`localhost` FUNCTION `member_networth` (
    `member_id` double
    ) RETURNS double BEGIN DECLARE networth DOUBLE;
    
    MySQL said: Documentation
    #1064 - 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 '' at line 3 
    

     

    any help will be appreciated

     

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