Forum Moderators: coopster
<a href="Link To page 1">Page 1 Name</a><br>
Page 2 Name<br>
<a href="Link to page 3">Page 3 Name</a>
So that it would show links to every page that is connected to that certain $article_id in the page url, except for the page your currently viewing.
Heres what I have so far:
$sql= "Select * from article_hubs";
$result = mysql_query($sql);
$article_hub_row = mysql_fetch_array($result);
$pages= $article_hub_row['pages'];
Then I have a table called review_pages which contains the "name" of the various pages in that article. I'm thinking a
while($row = mysql_fetch_array($result))
will need to be used. I have heard of "stopping" the foreach loop, and I think that is what will be needed to stop the loop when it reaches the current page that we're viewing and to just print the name of it.
Please someone help me, its just too much new php stuff i'm trying to process all at the same time hehe.
while control structure. For example:
while($row = mysql_fetch_array($result)) {
//do stuff
if(...) {
//do stuff
break;
}
}
2. The review_hubs table contains data on how many "pages" are in the review, the "name" of it, "id" of it, and thats mainly that is needed to tell. The review pages table contains the "name" of the page, id of it, and id of the review hub it belongs to. Thats really onl that needed for that table.
3. Yes
I have my page assigned like so, review.php?id=1&page=5 . You get the idea. Thx
Table: review_hubs
----------------------------------
review_id review_name nbr_of_pages
========= =========== ============
........1.....Review1............6
........2.....Review2............2
........3.....Review3............1
Table: review_pages
----------------------------------
review_id page_id page_name
========= ======= =========
........1.......1.....Page1
........1.......2.....Page2
........1.......3.....Page3
........1.......4.....Page4
........1.......5.....Page5
........1.......6.....Page6
........2.......1.....Page1
........2.......2.....Page2
........3.......1.....Page1
I have my page assigned like so, review.php?id=1&page=5
// make sure $_GET data is what you expect (numbers, etc.)
if (!is_numeric($_GET['page'])) exit('page must be numeric');
$sql =
"SELECT * FROM review_pages
WHERE review_id = '" . $_GET['id'] .
"' ORDER BY page_id";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$page_names[$row['page_id']]=$row['page_name'];
}
//if ($_GET['page'] < 0 or $_GET['page'] > count($page_names)) exit('Invalid page number');
$previous_page = (isset($page_names[$_GET['page'] - 10]))? $page_names[$_GET['page'] - 10] : '';
$current_page = $page_names[$_GET['page']];
$next_page = (isset($page_names[$_GET['page'] + 10]))? $page_names[$_GET['page'] + 10] : '';
if ($previous_page) {
print "<a href=\"Link To page " . ($_GET['page'] - 10) . "\">$previous_page</a><br>";
}
print "$current_page<br>";
if ($next_page) {
print "<a href=\"Link To page " . ($_GET['page'] + 10) . "\">$next_page</a><br>";
}
Notice I didn't use the total number of pages field whatsoever. You wouldn't have to store the total number of pages in the review_hubs table. It's tough to try and synchronize data this way, therefore I try not to practice this type of data storage (totals in one file based on number of detail records in another). I realize somebody is going to come along and argue about the performance of seeing the total in this single row versus counting rows every time, but trust me, somewhere down the line this practice will come and bite you in the rear -- usually with payroll or some other critical financial application. Somebody will let you know about it though and then there's egg on your face as well as writing a new application to sychronize your totals every night. Yeah, sure, I agree, real nice trade-off for performance...(sarcasm inserted purposely).
If it isn't an exact fit, at least you have a start. Post again if you need more help.
Regards -- coopster