1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Issue with php coding.

Discussion in 'PHP & Perl' started by Zoekban, Jan 21, 2015.

  1. Zoekban

    Zoekban Newbie

    Joined:
    Apr 23, 2013
    Messages:
    18
    Likes Received:
    0
    Good day!
    I'm using 2 scripts.
    I use it through a plugin for php n wordpress.


    1-
    $minutes = date('i');
    if($minutes<=15) {
    $total = "2";
    }elseif($minutes<=30){
    $total = "2";
    }
    $file_type = ".jpg";
    $image_folder = "image source";
    $start = "1";




    $random = mt_rand($start, $total);




    $image_name = $random . $file_type;




    echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";




    2-


    $total = "2";
    $file_type = ".jpg";
    $image_folder = "image source";
    $start = "1";


    $random = mt_rand($start, $total);


    $image_name = $random . $file_type;


    echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";




    And the problem I'm experiencing is that the images that the script should randomly display, are being kinda mixing with each other, Can you please check what the problem is with? because for example, If i try to make a table with those script, the table is getting mixed up and I can't work it out.
    Thanks from advanced.
     
  2. bigbadseo

    bigbadseo Newbie

    Joined:
    Jan 8, 2015
    Messages:
    15
    Likes Received:
    3
    Occupation:
    SEO, IT
    Location:
    secret
    mt_rand function uses integers and your variables $total and $start are strings. You should remove the quotation marks. They should look like this:

    $total = 2;
    $start = 1;
     
    • Thanks Thanks x 1