-2

I'm currently working on a project on my own, and everything went nice so far, but after changing a bit of my code, my grids aren't looking the way I want to. You cand see that there should be 3 columns, instead of only one, and I can't figure out why is this happening.

Thanks in advance!

 <div class="col-sm-4">
 <h4 class="card-title">Misiuni Active</h4>
 <div class="row">
                <?php
                $today = date("Y-m-d");
                $result = mysqli_query($conn,"SELECT * FROM misiuni");

                if(mysqli_num_rows($result)){

                while ($row = mysqli_fetch_assoc($result)) {

                    if ($today < $row['deadline']) {
                        echo '<form method="POST" action="accept.php">';
                        echo '<div class="ribbon-wrapper card">';
                        echo '<input type="hidden" name="titlu" value="' . $row['titlu'] . '"></input>';
                        echo '<div class="ribbon ribbon-default">' . $row['titlu'] . '</div>';
                        echo '<p class="ribbon-content">' . $row['misiune'] . '</p>';
                        echo '<center><br><h4 class="card-title">Reward:</h4></center>';
                        echo '<center><img src=' . $row['reward'] . ' width="200px" height="200px"></center>';

                        $sql = mysqli_query($conn,"SELECT * FROM misiuni_acceptate where username='". $_SESSION['username'] . "' AND titlu_misiune='". $row['titlu'] . "'");

                        if(mysqli_num_rows($sql)){

                            while ($row = mysqli_fetch_assoc($sql)) {

                                if($row['status']=='yes'){

                                    echo '<input type="submit" class="btn btn-info" value="Misiune finalizată" disabled>';

                                }else {

                                    echo '<input type="submit" class="btn btn-warning" value="Misiune în curs" disabled>';

                                }
                            }
                        }else {

                            echo '<input type="submit" class="btn btn-success" value="Acceptă misiunea">';

                        }

                        echo '</div>';
                        echo '</div>';
                        echo '</form>';


                    }
                }
            }

?>

              </div>
     </div>

Image here

  • 1
    At first glance, I don't see a `
    ` tag and it's hard to track the different tags to see which match up. What did you change that "broke" your project?
    – kchason Oct 27 '17 at 15:13
  • kchason beat me to it, and remember that if you have responsive and your browser is not large enough, it will "pile up" the div into a single column. If you stretch your browser larger, does it return to 3 columns? – Nic3500 Oct 27 '17 at 15:15
  • I added the part with the 2nd query and the separated submit buttons. No, it doesn't if I stretch the browser. – Andrei Cosmin Oct 27 '17 at 15:19
  • Wait your edit changes the whole thing! You first start with a col-sm-4, into which you fit a row only. You have to do this: declare a row, then inside that row, declare your col-sm-4. You really need to review bootstrap documentation and look at the sample code, you are all over the place :-) – Nic3500 Oct 27 '17 at 15:31
  • Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use prepared statements with bound parameters, via either the [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) drivers. [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examples. – Alex Howansky Oct 27 '17 at 15:39

1 Answers1

0
<div class="row">
<h4 class="card-title">Misiuni Active</h4>

<?php
                $today = date("Y-m-d");
                $result = mysqli_query($conn,"SELECT * FROM misiuni");

                if(mysqli_num_rows($result)){

                while ($row = mysqli_fetch_assoc($result)) {

                    if ($today < $row['deadline']) {
                        echo '<div class="col-xs-6 col-sm-3">'
                        echo '<form method="POST" action="accept.php">';
                        echo '<div class="ribbon-wrapper card">';
                        echo '<input type="hidden" name="titlu" value="' . $row['titlu'] . '"></input>';
                        echo '<div class="ribbon ribbon-default">' . $row['titlu'] . '</div>';
                        echo '<p class="ribbon-content">' . $row['misiune'] . '</p>';
                        echo '<center><br><h4 class="card-title">Reward:</h4></center>';
                        echo '<center><img src=' . $row['reward'] . ' width="200px" height="200px"></center>';

                        $sql = mysqli_query($conn,"SELECT * FROM misiuni_acceptate where username='". $_SESSION['username'] . "' AND titlu_misiune='". $row['titlu'] . "'");

                        if(mysqli_num_rows($sql)){

                            while ($row = mysqli_fetch_assoc($sql)) {

                                if($row['status']=='yes'){

                                    echo '<input type="submit" class="btn btn-info" value="Misiune finalizată" disabled>';

                                }else {

                                    echo '<input type="submit" class="btn btn-warning" value="Misiune în curs" disabled>';

                                }
                            }
                        }else {

                            echo '<input type="submit" class="btn btn-success" value="Acceptă misiunea">';

                        }

                        echo '</div>';
                        echo '</div>';
                        echo '</form>';
                        echo '</div>';


                    }
                }
            }

?>