0

Hi I am trying to write a script that puts a Horizontal Line between MySQL query results but doesn't show up after the last row.

eg:

First Line
----------------
Second Line
----------------
Third Line

I'm using PHP, MySQL and JavaScript AJAX. Don't know if that's relevant for this instance or not.

Any help would be appreciated.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by UzuNarU
0

I think what you want to do is something a long the lines of this;

$result = mysql_query("select * from table");
$counter = 0;
$rowcount = mysql_num_rows($result);
while($row=mysql_fetch_array($result)) { 
  echo "process row data";  
  if ($count < $rowcount) {
    echo "<hr />";
  }
  $counter++
}

Hope that helps.

Edited by scaiferw: n/a

0

Here's an example:

$res = mysql_query("SELECT * FROM `table`");
$count = 0;
$num = mysql_num_rows($res);
while ($r = mysql_fetch_array($res))
	{
	$count++;
	// echo some data:
	echo $r['something'];
	if ($count < $num)
		{
		echo "<hr/>";
		}
	}
0

Thanks, everyone. I was actually able to figure it out :P. Umm here's my code I think it's similar to the examples I received.

$rowcount = 1;

if ( mysqli_num_rows($result) == $rowcount){
	echo "Last Row";
} else {
        echo "Rows" .
        "<hr style='color:#00FF00;' />";
        $rowcount = $rowcount + 1;
}

Edited by UzuNarU: forgot a line of code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.