Page 1 of 1
Accessing the next title
Posted: Fri Sep 14, 2007 3:10 am
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
Posted: Fri Sep 14, 2007 3:12 am
by superdezign
Show some code. The while loop tends to handle data retrieval from the database for us.
Posted: Fri Sep 14, 2007 3:16 am
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
Posted: Fri Sep 14, 2007 3:55 am
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.
Posted: Fri Sep 14, 2007 4:26 am
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