lundi 18 février 2019

SQL Select In Random Order BUT Do Not Select Duplicate From A Specifc Column

Ok so I have my database that has multiple ads...BUT I have multiple ads from the same site that have been added....here is an example.

enter image description here

As you can see...the database has two links that are different...but they lead to the same site. My goal is to have it RANDOMLY select one of them and display it but not the other WHILE ALSO selecting all of the others and displaying those as well. Here is the coding I have at the moment for it:

<?php
$query = 'SELECT * FROM `ads`';
        $results = mysqli_query($connect, $query) or die(mysql_error());
        while ($row = mysqli_fetch_array($results, MYSQLI_ASSOC)) {
            extract($row);
            echo '
                <div class="col-sm-6">
                <div class="card mb-30"><a class="card-img-tiles" href="'.$link.'">
                    <div class="inner">
                      <div class="main-img"><img src="'.$image.'" alt="'.$alt_title.'"></div>
                    </div></a>
                  <div class="card-body text-center">
                    <h4 class="card-title">'.$name.'</h4>
                    '.$about.'
                    <a class="btn btn-outline-primary btn-sm" href="'.$link.'">Check It Out</a>
                  </div>
                </div>
              </div>
            ';
            }
?>

I want it to display the circled ones randomly selected but not both for each set.

enter image description here




Aucun commentaire:

Enregistrer un commentaire