i have here a code for the selection of all the data from the database, here’s my code:
<?php
$name = $_POST['cname'];
if ($_POST["Search"] == "Search") {
$query = mysql_query("SELECT * FROM parts WHERE cname LIKE '%$name%'");
if (!empty($query)) {
$vsi = 'No Data';
$date = 'No Data';
$cname = 'No Data';
}
while ($row = @mysql_fetch_array($query)) {
$vsi = $row["vsi"];
$date = $row["date"];
$cname = $row["cname"];
}
and here is how i echo all the variables,
<tr class="gradeC">
<?php echo "<td width='10%'><font size='-2'> $vsi </font></td>" ?>
<?php echo "<td width='20%'><font size='-2'>$date</font></td>" ?>
<?php echo "<td width='20%'><font size='-2'> $cname</font></td>" ?>
</tr>
My problem is that,
i only get one result from each row but my data in the database are 5.
here is my result
vsi date name
123 12/12/2012 test1
but the correct result should be:
vsi date name
123 12/12/2012 test1
123 12/12/2012 test1
123 12/12/2012 test1
123 12/12/2012 test1
123 12/12/2012 test1
note,
i make all the data in the database all the same
You have to use TR in while loop.
Warning
your code is vulnerable to sql injection you need to escape all
getandpostand the better approach will be using Prepared statementGood Read
Note
ext/mysqlPHP extension, which provides all functions named with the prefix mysql_, is officially deprecated as of PHP v5.5.0 and will be removed in the future. So use eitherPDOorMySQLiGood read
I Hope this helps.