We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Horizontal Line Between MySQL Query Results

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
1 Hour
Discussion Span
2 Years Ago
Last Updated
4
Views
Question
Answered
UzuNarU
Light Poster
47 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

scaiferw
Junior Poster
115 posts since May 2010
Reputation Points: 25
Solved Threads: 7
Skill Endorsements: 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/>";
		}
	}
SikoSoft
Junior Poster in Training
55 posts since May 2010
Reputation Points: 14
Solved Threads: 8
Skill Endorsements: 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;
}
UzuNarU
Light Poster
47 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by SikoSoft and scaiferw

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0693 seconds using 2.65MB