1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with a PHP script that is not working correctly.

Discussion in 'PHP' started by gibsongk55, Sep 4, 2010.

  1. #1
    Hi,

    I have been kicking myself in the butt trying to get this to work. This script should display images on a page. There are 10 spots to display and it should randomly choose them if more than 10 results. It works but the problem is, it is not checking a field for what I want to display. Before I changed the script it chose all records so it always display 10. I added in to check if gold = 1 which it should only come up with 4 records or images. Now it shows none. I'm not very good at php but it seems it should work.

    The only changes I made are "WHERE gold = 1" on line 6 and "AND dle_post.gold = 1" on line 11

    Any help would be appreciated.

    <?php
    function dle_img () {
        global $db;
        
        $arr_Out = array();
        $result = $db->query("SELECT id,title,approve,gold FROM dle_post WHERE gold = 1 ");
        while ($row2 = $db->get_row($result)) {
            $title_id[$row2['id']] = stripslashes($row2['title']);
        }
        
    $result = $db->query("SELECT * FROM dle_images RIGHT JOIN dle_post ON dle_images.news_id = dle_post.id where dle_post.approve = 1 AND dle_post.gold = 1 ORDER BY RAND()  LIMIT 20");
    
     // $result = $db->query("SELECT * FROM dle_images  ORDER BY RAND()  LIMIT 10");
    
    
        $imgar = array ();
    $i = 1;
     while (  $row = $db->get_row($result)) {
            $images = $row['images'];
            if (in_array($images, $imgar)) continue;
         $imgar[] = $row['images'];
            $images = explode("|||",$images);
    $images = $images[0];
    if (file_exists(ROOT_DIR."/uploads/posts/".$images)) {$file_dir = "posts";}
            else {$file_dir = "files";}
    
            $title = substr($title_id[$row['news_id']],0,25)."...";
           
    if(empty($row['news_id'])) {
    
    
     $out .= "<table align=\"center\"><tr><td align=\"center\">
            <table cellpadding=\"0\" cellspacing=\"0\" style=\"margin-right:10px\" height=\"135\">
            <tr>
            <font face=\"arial\" size=\"1\" color=\"#000000\">{$title}</font></cetner></b></td>
            </tr>
            <td style=\"background-color:#000000\">
            <div style=\"height:2px\"></div>
            <a href=\"/index.php?newsid=15\">
            <img border=\"0\" src=\"http://www.mysite.com/uploads/posts/2009-11/1257104707_cca50ef_01.jpg\" width=\"150\" height=\"95\" title=\"{$title}\"></td>
            </td>
            </table>
            <p><p><p>
            </a></td></tr></table>";
    }
    else
    {
     $out .= "<table align=\"center\"><tr><td align=\"center\">
            <table cellpadding=\"0\" cellspacing=\"0\" style=\"margin-right:10px\" height=\"135\">
            <tr>
            <font face=\"arial\" size=\"1\" color=\"#000000\">{$title}</font></cetner></b></td>
            </tr>
            <td style=\"background-color:#000000\">
            <div style=\"height:2px\"></div>
            <a href=\"/index.php?newsid={$row['news_id']}\">
            <img border=\"0\" src=\"/uploads/".$file_dir."/{$images}\" width=\"150\" height=\"95\" title=\"{$title}\"></td>
            </td>
            </table>
            <p><p><p>
            </a></td></tr></table>";
    }
           
    if($out)
    {
     if($i == 5) {$arr_Out[] = $out; $out = '';}
     if($i == 10) {$arr_Out[1] = $out; $out = '';}
            $i++;
    }
    }
        return $arr_Out;
    }
    
    $dle_img = dle_img();
    
    
    
    ?>
    Code (markup):
     
    Last edited: Sep 4, 2010
    gibsongk55, Sep 4, 2010 IP
  2. gibsongk55

    gibsongk55 Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Strange I had someone test the script and he says the Mysql commands are not working 100% sure. But I do a query on both MySql commands in the above script and they both return 4 rows.

    Gibs
     
    gibsongk55, Sep 9, 2010 IP
  3. gibsongk55

    gibsongk55 Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's fixed. A little modification to the sql command and tweaking the php code as well. =)


    Gibson pats himself on the back!
     
    gibsongk55, Sep 11, 2010 IP