y2yang Posted May 5, 2009 Share Posted May 5, 2009 Need for php to get field before current field and field after current field from mysql, sort of like a next and previous, only they're text file. Example: There are two of this in my HTML table: <?php print $row['title_main']; ?> I want the first one to do something like this: <?php print $row['title_main'] + 1; ?> And the second one to : <?php print $row['title_main'] -1; ?> Here is my code: <tr style="height:25px;"> <td><img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_prev.gif" class="vam" alt="" /></td> <td class="tal fc14"><span style="margin:0 0 0 5px;"><a href="read.php?nPageNo=<?php echo $_GET['nPageNo']; ?>&Article=<?php print $prevpage; ?>"><?php print $row['title_main']; ?></a></span></td> </tr> <tr style="height:1px;"><td colspan="2" class="bgc9"></td></tr> <tr style="height:25px;"> <td><img src="http://image.vickizhao.net/style_guide/icn/icn_starhome_next.gif" class="vam" alt="" /></td> <td class="tal fc14"><span style="margin:0 0 0 5px;"><a href="read.php?nPageNo=<?php echo $_GET['nPageNo']; ?>&Article=<?php print $nextpage; ?>"><?php print $row['title_main']; ?></a></span></td> </tr> I got nPageNo to get the correct link id but not the Article. Here is my query: <?php // Connect to DB. // find out how many rows are in the table $query = "SELECT COUNT(*) FROM info_all"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $img_per_page = 1; // find out total pages $totalpages = ceil($numrows / $img_per_page); // Get current page or set a default. if (isset($_GET['Article']) && is_numeric($_GET['Article'])) { // cast var as int $Article = (int) $_GET['Article']; } else { // Default page number. $Article = 1; } // end if // if current page is greater than total pages... if ($Article > $totalpages) { // set current page to last page $Article = $totalpages; } // end if // if current page is less than first page... if ($Article < 1) { // set current page to first page $Article = 1; } // end if // Get table information. $query = "SELECT * FROM info_all WHERE Article=$Article"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $row = mysql_fetch_assoc($result); // Get previous page number. $prevpage = $Article + 1; // Get next page. $nextpage = $Article - 1; ?> The code I used to get my nPageNo id is // Get previous page number. $prevpage = $Article + 1; // Get next page. $nextpage = $Article - 1; and I used <?php print $prevpage; ?> to get previous id <?php print $nextpage; ?> to get next id I would like to achieve something similar to <?php print $row['title_main']; ?> Link to comment https://forums.phpfreaks.com/topic/156898-how-to-get-this-rowtitle_main-to-have-a-1-and-1-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.