Hello, I am pretty new at php coding so i have a question now. <a href="test-<?php echo $row_bastir['page']-1; ?>.htm"><< Previous <?php echo $row_bastir['page']-1; ?> PHP: page is the name of the id table, at the table there is ids from 1 to 300 And the code above is for previous id. For example if you are at id 5's page, by clicking the link at the bottom of the page, you can go to id 4's page. Practically it works but, when you are at id 1's page, that link will say go to id 0's page which does not exist. So i want to add some controlling way to code, so first it checks if id-1 is available, if it is not it wont display the link otherwise it will show the link for previous page.
Just check to see if its equal to 1 prior to the link. Do it before the a href, since you would skip the entire thing. <?php $page = $row_bastir['page']; if($page != 1) { echo "whole line"; } else { echo "previous link only"; }
<?php $page = $row_bastir['page']; if($page != 1) {echo "<a href="test-<?php echo $row_bastir['page']-1; ?>-.html"><< Test <?php echo $row_bastir['page']-1; ?> Page</a>";} else { echo "previous link only"; } ?> PHP: Is it like that? Because i am using dreamweaver and i guess i made a mistake at somewhere because code colors are not changing anymore.
You are mixing the tags up. If you put <?php you have to have ?> before you start another. Plus its pretty blasted confusing all on a single line. <?php $page = $row_bastir['page']; if($page != 1) { echo "<a href=\"test-" . $page-1 . "-.html\"><< Test" . $page-1 . "Page</a>"; } else { echo "previous link only"; } ?> PHP: Which still isn't best but it should work. You have to put in the "next" page as well in the first half of the IF and replace the "previous link only" but get it working first. Further, if you use " to enclose the PHP statement, when you use " inside that statement it has to be escaped with the \. Which would have caused you more grief.
Hello, I tested the code, but $page-1 part is making problem it is showing a text instead of url, when i change it to $page, it works like a charm so the problem is $page-1 part.
well assign it to $prevPage: $prevPage = $page -1; Before you enter the if part. Then put $prevPage in place of the $page - 1 <?php $page = $row_bastir['page']; $prevPage = $page -1; if($page != 1) { echo "<a href=\"test-$prevPage-.html\">Test $prevPage Page</a>"; } else { echo "previous link only"; } ?> Code (markup):
thanks how can i make it for the next page? because i tried to change - to + but even there is no record with the next id, it shows the link.
<?php $page = $row_bastir['page']; $prevPage = $page -1; $nextPage = $page + 1; if($page != 1) { echo "<a href=\"test-$prevPage-.html\">Test $prevPage Page</a>"; echo "<a href=\"test-$nextPage-.html\">Test $nextPage Page</a>"; } else { echo "<a href=\"test-$nextPage-.html\">Test $nextPage Page</a>"; } ?> Should do it.