OVERVIEW:
So, I'm working on a sort of "search script" to help users find data based upon 2 different types of data. They can search by Category or by Encoding grabbed from my database.
Problem:
The array only returns 1 row, while there are 3 (exact) duplicates in my database, problem still occurs if the entries are different.
Code Snippet:
<?php
$catagory = mysql_real_escape_string($_GET['c']);
$encode = mysql_real_escape_string($_GET['e']);
$query = "SELECT * FROM posts WHERE ";
if(!empty($catagory)) {
$query =$query . "catagory = '$catagory'" ;
}
if(!empty($encode)) {
if(!empty($catagory)) {
$query = $query . " AND " ;
}
$query = $query. "urlencode = '$encode'" ;
}
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
if (empty($row)) {
$message = "Sorry, there were no results";
echo $message;
} ELSE {
echo '<table>';
echo '<thead>';
echo '<th>Title</th><th>Posted</th><th>Address</th><th>Views</th>';
echo '</thead>';
echo '<tbody>';
$now = date('Y-m-d H:i:s');
while($row = mysqli_fetch_array($result)) {
$title = htmlspecialchars($row['titlepre']);
echo $row['titlepre'];
$posted = dateDiff($row['date'],$now);
$address = $row['address'];
$views = $row['views'];
$url = $row['url'];
echo '<tr><td><a href ="'.$url.'">'.$title.'</a></td><td>'.$posted.'</td><td>'.$address.'</td><td>'.$views.'</td></tr>';
}
echo '</tbody>';
echo '</table>';
}
?>
Database Information
| ID | address | title | titlepre | content | Catagory | url | urlencode | views | date -------------------------------------------------------------------------------------------------- | 3 |[WITHHELD]| title | title | content | Rants - Things | HDyLkl | Scheme | 1 |2013-11-28 | | 5 |[WITHHELD]| title | title | content | Rants - Things | HDyLkl | Scheme | 1 |2013-11-28 |
Now, I'm fairly new to PHP, so please bear with me if my code isn't 100% efficient.
mysqlandmysqli? Why don't you use prepared statements instead if usingmysqli?