Reputation: 13
I wrote code that allow me to get information from mysql using mysql which is old code, and i tried to change to mysqli from mysql but some how is not working right, I believe that i'm still new to learn about mysqli, can any one help me to to write into mysqli from mysql so i can learn myself from there please... here is code...
thanks...
<?php
include('db.php');
?>
<?php
if(isset($_POST['kw']) && $_POST['kw'] != '')
{
$kws = $_POST['kw'];
$kws = mysql_real_escape_string($kws);
$query = "select * from product where product_name like '%".$kws."%' limit 10" ;
$res = mysql_query($query);
$count = mysql_num_rows($res);
$i = 0;
if($count > 0)
{
echo "<ul>";
while($row = mysql_fetch_array($res))
{
echo "<a href='$row[product_name]'><li>";
echo "<div id='rest'>";
echo $row['product_name'];
echo "<br />";
echo "<td>";?><img src="<?php echo $row["screenshot"];?>" height="100" width="100" <?php echo "</td>" ;
echo "</div>";
echo "<div style='clear:both;'></div></li></a>";
$i++;
if($i == 5) break;
}
echo "</ul>";
if($count > 5)
{
echo "<div id='view_more'><a href='#'>View more results</a></div>";
}
}
else
{
echo "<div id='no_result'>No result found !</div>";
}
}
?>
Upvotes: 0
Views: 171
Reputation: 157870
The general rule of thumb is:
But write mysqli version from scratch.
As your approach with old mysql ext were all wrong, do not translate it to new mysqli. Just learn mysqli and then write the whole thing from scratch.
Otherwise you'd better leave your old code as is, just because such a mechanical rewriting will do not a slightest good.
Upvotes: 3