Jump to content

How to get this $row['title_main'] to have a +1 and -1 function.


y2yang

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.