Accessing the next title

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Accessing the next title

Post by kkonline »

I access the current page title as $row['title']; which is within a while loop.

Now how do i access the title of the next row in database? something like $row['title'+1]; gives me an output as 1
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Show some code. The while loop tends to handle data retrieval from the database for us.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post by kkonline »

superdezign wrote:Show some code. The while loop tends to handle data retrieval from the database for us.

Code: Select all

$countviews = mysql_query("UPDATE wow SET views=views+1 WHERE id=$page");
$sql = mysql_query("SELECT * FROM wow WHERE `trusted` = 0 ORDER BY `id` ASC LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){


    echo "<!--start-->";                
    echo "<font size=3><b>";
    echo $row['title']."</b><br /></font>";
    echo "<font size=2>";
    echo "Contributed By ";    
    echo $row['contributed_by'];
    echo " on ";
    echo date("jS F Y H:i:s", $row['date'])."<p>";    
    echo $row['content']."</p><br />";
    echo "<!--end-->";
}echo $safeurl->make_safe_url($row['title']+1);
 //should give me the next title
In the above code echo $safeurl->make_safe_url($row['title']); displays the current title but i want to display the title of the next row in the database
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Do you understand what this line is doing:

Code: Select all

while ($row = mysql_fetch_array($sql)) {
:?:

It gets the rows one by one and replaces $row with the current row's data. Within the while loop, everything that you do with $row is done to a particular row's data in your result set. After there are no more rows, $row == null, thus the while loop ends.

$row is no longer usable after the loop until you assign some other value to it.
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Post by kkonline »

Yes sir, i understand what it does completely... i am using a mod rewrite structure as example.com/abc/1/2/3/content-title-of- page-1 and when the user clicks on the next button it should point to example.com/abc/1/2/3/content-title-of- page-2 that means content-title-of- page-2 etc. is the title of the next page

example the page looks like

Code: Select all

within the while loop{

TITLE of current page

CONTRIBUTED BY abc

on some DATE

CONTENT 
}

<< Previous Page ------ Next Page>>
now in the above example the next page link (url will have the title of the next page according to the mod rewrite i have used in combination with scottayys human rich code posted on the forum) so how to display the link for next and previous
Post Reply