theone Posted April 9, 2006 Share Posted April 9, 2006 Right...[code]<?mysql_connect($db_host, $db_user, $db_pass);mysql_select_db($db_name);$sql = "SELECT * FROM news_site WHERE `show` = '1'";$results = mysql_query($sql);while ($data = mysql_fetch_array($results)) { var_dump($data); print "<hr>";}?>[/code]Now that will fetch small news articles from the database, like a blog style. What i want to do is on the last row it prints, i want to drop the print "<hr>".I cant do it based on a predifned number as the number of rows is not specified cos it depends on the number or news articles.How do i do that? Or isnt it possible?Thanks all,Dave Quote Link to comment Share on other sites More sharing options...
theone Posted April 9, 2006 Author Share Posted April 9, 2006 The only way i can think of doing it would be to count the number of rows... etc. But is there a simpler way than that? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 9, 2006 Share Posted April 9, 2006 two ways you can do this - one you have identifed the other... well I think a bit more messy but each to their own.counting method...[code]<?phpmysql_connect($db_host, $db_user, $db_pass);mysql_select_db($db_name);$sql = "SELECT * FROM news_site WHERE `show` = '1'";$results = mysql_query($sql);$count = mysql_num_rows($result);$i = 1;while ($data = mysql_fetch_array($results)) { var_dump($data); if ($i++ != $count) print "<hr>";}?>[/code]'messy' method[code]<?phpmysql_connect($db_host, $db_user, $db_pass);mysql_select_db($db_name);$sql = "SELECT * FROM news_site WHERE `show` = '1'";$results = mysql_query($sql);$data = mysql_fetch_array($results);var_dump($data);while ($data = mysql_fetch_array($results)) { print "<hr>"; var_dump($data);}?>[/code]I prefer the former as the code is neater but the latter is probably (very slightly) more efficient in terms of resource use as there is no evaluaion of an if statement or the looping increment of $iHave fun ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.