Jump to content

While


user4fun

Recommended Posts

here is what I have so far, it does not show the no record

$i=1;while($row = mysql_fetch_array($result))	{	echo $i . "-";		 if (is_null($row['Ad_Name']))		 {		 echo " No record";		 } 		 else		 {		 echo $row['Ad_Name'];		 }	 echo "</br>";	 $i++;		 if ($i==8)		 {		 break;		 }		 	 }?>

Link to comment
Share on other sites

You could split it into two loops:$i=1;while($row = mysql_fetch_array($result)) { echo $i . "-"; echo $row['Ad_Name']; echo "</br>"; $i++; if ($i==8) { break; } }for($x = (8-$i); $x < 8; $x++) {echo 'No record';}

Link to comment
Share on other sites

Tat sounds good except taht it needs some fine tuning.The results are now1-Start3End42-Start4End53-Start5End64-Start7End8No recordNo recordNo recordNo recordNo record I want the result to look like this1-Start3End42-Start4End53-Start5End64-Start7End85- No record6- No record7- No record8- No record

Link to comment
Share on other sites

}for($x = (8-$i); $x < 8; $x++) {echo $x.'No record<br />';} That one you should have got on your own, tbh.

Link to comment
Share on other sites

I did that alraedy,, it is displaying more records than I want. That is why I asked again, sorryI am still playing with it

$i=1;while($row = mysql_fetch_array($result)){echo $i . "-";echo $row['Ad_Name'];echo "</br>";$i++;if ($i==8){break;}}if ($i<8){$r = (8-$i);for($x; $x == $r; $x++) {echo $i . "-";echo "No record";echo "</br>";$i++;}}

Link to comment
Share on other sites

oh, well change instances of 8 with 7.

Link to comment
Share on other sites

for($x; $x ***==*** $r; $x++)

Link to comment
Share on other sites

I know it was...the asterisks enclose the area you need to think about. Compare and contrast with the original for loop I showed you.

Link to comment
Share on other sites

I want to stop a while loop after it displays 7 records. If there is only 4 records that it displayed, then it would fill in line 5, 6, and 7 with "No records"Any help would be great.
$result = mysql_query("SELECT items FROM table LIMIT 7"); // <-- Your query, limiting 7 is optional$i = 0;while ($i < 7) {   $item = mysql_result($result,$i,'Ad_Name');   if (!empty($item)) {	  echo "<br>$item";   } else {	  echo "<br>No Record";   }   $i++;}

Hope it helps :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...