Jump to content

While


user4fun
 Share

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;		 }		 	 }?>

Edited by user4fun
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++;}}

Edited by user4fun
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++)

Edited by chibineku
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 :)

Edited by Kameloh
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...