Monday 3 September 2018

The mysql query does not work correctly:

I have problem making this to work. I wannt to select row from database and render it to list. This is my code:

<ul class = "list">
  <li>
  <?php
    $x = 'some_string';
    $title = 'title';

    $dbc = mysqli_connect('localhost', 'root', '', 'database') or die('Error connecting');
    $query = "SELECT * FROM table WHERE column ==$x ORDER BY procenat DESC LIMIT 5";
    $data = mysqli_query($dbc, $query);
  ?>
   <div id = "listdiv">
  <?php
    while ($row = mysqli_fetch_array($data)) {
  ?>
    <h4><?php echo $row[$title]; ?> </h4>
  <?php
    }
    mysqli_close($dbc);
  ?>
   </div> </li> </ul>

I tried with LIKE '%$x%' and that didn't work as well. And i tried ... column = $x

You need to use single equal sign along with quotes.
    $query = "SELECT * FROM table WHERE column = '$x' ORDER BY procenat DESC LIMIT 5";

0 comments:

Post a Comment