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.

How to display random image and text from MySQL

Discussion in 'PHP' started by Tuhin1234, Mar 10, 2015.

  1. #1
    <?php
    require_once('config.php');
    $dbconnect = new db();
    $dbconnect->connect();
    ?>
    <html>
    <head>
    <title><?php echo $site_title; ?></title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta name="description" content="<?php echo $site_meta_description; ?>" />
    <meta name="keywords" content="<?php echo $site_meta_keywords; ?>" />
    <meta name="author" content="<?php echo $site_meta_author; ?>" />
    <link rel="stylesheet" type="text/css" href="../css/styles.css" />
    <script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.8.18.custom.min.js"></script>
    <link type="text/css" href="../css/smoothness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
    <script>
    $(function() {
    $( "#selectable" ).selectable({
    selecting: function(event, ui) {
    $(ui.selecting).find(':checkbox').attr('checked', true);
    },
    unselecting: function(event, ui) {
    $(ui.unselecting).find(':checkbox').attr('checked', false);
    }
    });

    });
    </script>

    <script>
    $(function() {
    $( "input:submit, a, button", ".moderate_images" ).button();
    });
    </script>

    <!-- POPUP BOX CLICK IMAGE START -->
    <script language="javascript" type="text/javascript">
    <!--
    function popitup(url) {
    newwindow=window.open(url,'name','height=800,width=1024,resizable,scrollbars');
    if (window.focus) {newwindow.focus()}
    return false;
    }

    // -->
    </script>
    <!-- POPUP BOX CLICK IMAGE END -->

    </head>
    <body>



    <form action="search_moderate.php" method="POST">
    <div id="content">
    <div id="selectable" class="all_images">
    <?php
    $filters = "";
    $paginationFilter = "";
    if(isset($_GET['id_user']) && is_numeric($_GET['id_user'])) {
    $filters .= " WHERE id_user = {$_GET['id_user']}";
    $paginationFilter .= "&id_user={$_GET['id_user']}";
    }

    $qNum = "SELECT id FROM images $filters";
    $resultNum = mysql_query($qNum);

    $rowsnumber = mysql_num_rows($resultNum);
    if($rowsnumber < 1) {
    $rowsnumber = 1;
    $no_entries = true;
    }

    //PAGINATION SCRIPT
    $p = new pagination();
    $arr = $p->calculate_pages($rowsnumber, 20, $pageid);
    $sql_limit = $arr['limit'];





    $q = "SELECT images.view_id, images.views, images.name, images.date_added, images.ftp, sources.thumb2, sources.img2, ftp_logins.url FROM images
    INNER JOIN sources ON images.source=sources.id
    LEFT JOIN ftp_logins ON images.ftp = ftp_logins.id $filters
    ORDER BY images.id DESC
    $sql_limit";
    $result = mysql_query($q);
    while($rowImages = mysql_fetch_assoc($result)) {
    if($rowImages['ftp'] > 5) {
    $real_site_url = $rowImages['url'];
    } else {
    $real_site_url = $site_url;
    }

    echo "<li class='ui-state-default'>";
    $dirDate = preg_replace('/-/', '/', $rowImages['date_added']);
    $dirThumb = $real_site_url . "/" . $rowImages['thumb2'] . "/" . $dirDate . "/" . $rowImages['name'];
    $dirImg = $real_site_url . "/" . $rowImages['img2'] . "/" . $dirDate . "/" . $rowImages['name'];
    echo "<div class='img_and_text'>
    <input type='checkbox' name='imagesidarr[]' style='display:none;' value='{$rowImages['view_id']}' />


    <a href='/img-{$rowImages['view_id']}.html'><img src='{$dirThumb}' /></a>

    </div>";
    echo "</li>";
    }


    ?>


    </div>
    </div>

    </form>


    </body>
    </html>
    this code show first 20 image But i want show image from Different imgae id .
     
    Tuhin1234, Mar 10, 2015 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Please use the code tags [ code ]
     
    EricBruggema, Mar 14, 2015 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    1) what is your db() object, and why does it have a connect method?

    2) stop opening and closing PHP willy-nilly. (seriously, they need to remove PHP shorttags from the language entirely, no more <?php ?> crap!)

    3) You might want to make it work BEFORE you start throwing bloated garbage like jQuery and pointless scripttardery at it.

    4) and IF you're going to have that pointless scripttardery, get it the devil out of the markup so it can be CACHED.

    5) You might find it easier to flip your single and double quotes so the code is clearer and processes faster.

    6) You appear to be blindly pasting values into your query strings with NO sanitation. This makes me think you are still using the mysql_ functions like it's still 2005. Since you are blindly dumping in $_GET... Yup, there it is, mysql_query -- so literally kiss anything remotely resembling security goodbye as, well... you have none!

    Not sure exactly what you're trying to accomplish with this, but the bizzare markup and even stranger PHP is a mish-mash of outdated practices and insecure methodologies - none of which makes the least bit of sense. From the JOIN garbage in the query and unusually complex SELECT, it also looks like whatever this is got WAY too complex for it's own good.

    Could you better explain what this is even supposed to do?
     
    deathshadow, Mar 14, 2015 IP
  4. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #4
    I disagree with the opening and closing, its a scripting language that needs to be combined with html/xml/rss or whatever. But the point is right, if you do it many times, its time to search for a better solution (seperate php and template pieces). But for small scripts its the best thing to do..
     
    EricBruggema, Mar 15, 2015 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    And that's what we have echo/print and similar functions for. No need to start and exit PHP every other line.
     
    PoPSiCLe, Mar 15, 2015 IP
  6. Tuhin1234

    Tuhin1234 Active Member

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #6
    Done By only simple change

    ORDER BY images.id DESC
    replaced by
    ORDER BY rand()
     
    Tuhin1234, Mar 15, 2015 IP
  7. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #7
    I do not totaly agree, as the shorttags are not created for no reason! :) and echo/printing piles of html is just not done...
     
    EricBruggema, Mar 15, 2015 IP