ARUN.G ARUN.G - 6 months ago 11
SQL Question

PHP Mysql always NEED to return 5 rows even 3rows present in table

Hi i need 5 rows count always in

Mysql select query


I My current output is

 

my query
----------------------
$query = mysql_query("select * from table_name where MOBILE='$mobile_no' order by ID LIMIT 5 ");
----------------------
Result
----------------------
ARUN - 987654321
VINO - 987654321
RAJA - 987654321

-------------------

But I need like this (Need to return empty rows)
----------------------
ARUN - 987654321
VINO - 987654321
RAJA - 987654321
0 - 0
0 - 0
-------------------



So that I can create
html table row
(always 5 rows)
text box
with empty value inside the
  while loop -----  while($row=mysql_fetch_array($query))  

Answer

You can use a loop in php and a counter in the loop. If the count is less then 5, then you fill the text box with nothing. It will give you something like that

$count = 0;
while($row=mysql_fetch_array($query)) {
    // Fill your text box
    $count+=1;
}
for($i=count; $i <= 5; $i++) {
    // Fill your text box with empty string or whatever.
}