|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
limiting the number of records and prev and next links
I have a page that retrieves a list of journals. I wanted to limit the records and also alternate the colours of each returned row...but my code isnt working i've messed about with it for ages but cant see what I've done wrong...can anyone help?
heres part of my code: <?php function rowcolor($j){ $bg1 = "#FF9933"; // color one $bg2 = "#FFFF99"; // color two if ( $j%2 ) { return $bg1; } else { return $bg2; } } ?> <?php $dbcon=pg_connect("------- user=wwwuser dbname=--- password=wwwuser"); if(!isset($start)) $start = 0; $sql = "SELECT count(*) as count FROM journals"; $result = pg_exec($sql); $rows = pg_numrows($result); $numrows = $rows['count']; if($start > 0) echo "<a href="" . $PHP_SELF . "?start=" . ($start - 10) . "">Previous</a><BR>n"; if($numrows > ($start + 10)) echo "<a href="" . $PHP_SELF . "?start=" . ($start + 10) . "">Next</a><BR>n"; if($rows != 0) { print "The site currently has $rows Journals please feel free to browse:<br>n"; ?> <table border=0><tr><th><a href="ordauth.php" title="order by author name"><font color="#000000">Author</font></a><th><a href="ordtitle.php" title="order by journal title"><font color="#000000">Title</font></a><th><a href="ordissue.php" title="order by Issue number"><font color="#000000">Issue</font></a><th><a href="ordformat.php" title="order by format type"><font color="#000000">Format</font></a> <?php for($j=0;$j<$rows;$j++) { $row = pg_fetch_array($result); print "<tr bgcolor=".rowcolor($j)."><td>" . $row["author"]; if($row["url"]){ print "<td><a href=".$row["url"].">{$row['title']}</a>n"; }else{ print "<td>" . $row["title"]; } |
|
#2
|
|||
|
|||
|
RE: limiting the number of records and prev and next links
To limit number of records returned by a SQL query, you could use LIMIT command.
ex: "SELECT * FROM myTable WHERE myName='Mike' LIMIT 1,5" |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > limiting the number of records and prev and next links |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|