-2

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

Adarsh M Pallickal
  • 813
  • 3
  • 16
  • 37
user3477366
  • 111
  • 1
  • 2
  • 6

4 Answers4

0

You need to use single equal sign along with quotes.

    $query = "SELECT * FROM table WHERE column = '$x' ORDER BY procenat DESC LIMIT 5";
Achshar
  • 5,153
  • 8
  • 40
  • 70
  • again not working. I dont think the problem is with query since i tried almost anything. – user3477366 May 12 '14 at 04:53
  • 1
    Then load up phpmyadmin and make sure your query executes. Once we are done with that we will know for sure that the problem is on php's side. – Achshar May 12 '14 at 04:55
0

You should use LIKE operator like this

$query = "SELECT * FROM table WHERE column_name LIKE '%$x%' ORDER BY procenat DESC LIMIT 5
Ramki
  • 519
  • 2
  • 9
0

Change the query line as shown below

$query = "SELECT * FROM table WHERE column = '".$x."' ORDER BY procenat DESC LIMIT 5";
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
Ramki
  • 519
  • 2
  • 9
0

There are two mistake in your query just try this one.

  1. replace $x with '$x'
  2. replace == with =
  3. run your query
$x = 'some_string';

$query = "SELECT * FROM table WHERE column ='$x' ORDER BY procenat DESC LIMIT 5";
slavoo
  • 5,798
  • 64
  • 37
  • 39
dev4092
  • 2,820
  • 1
  • 16
  • 15