y2yang Posted May 3, 2009 Share Posted May 3, 2009 How to make the number in red change on different page? <?php $page_id = "photo_23"; ?> This code is used on an iframe page. I wanted the number in red to change on every page, as it defined the comment page to its article. Parent page code: <div id="viewComment" style="display: block;"> <iframe style="height: 118px; width: 580px;" src="comment/news_1.php" name="ifrmComment" id="ifrmComment" scrolling="no" width="580" frameborder="0"></iframe> </div> Iframe page code (news_1.php): <?php $page_id = "photo_1"; ?> Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/ Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 If everypage is going to be numbered as above, so the second page would be news_2.php you can just use $_SERVER["SCRIPT_FILENAME"] <?php $page = (int) $_SERVER["SCRIPT_FILENAME"]; $page_id = "photo_$page"; Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824827 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 Would it be possible to have just one news page and have the script to generate increment int in the script instead of having to have the script to refer to the page name for it id? Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824830 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 If you only have one news page, you must have a way of going to the 'next' page, like next.php?page=2 Then you can use the $_GET global Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824832 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 how do i implement the $_GET global to make it work? Yes every page has it own ?page=# The thing is that news page is inside an iframe on ?page=# will it still work? Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824834 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 It will yes. news.php should have this somewhere; if(!isset($_GET['page'])) { $page = 1; } else { $page = (int) $_GET['page']; } Then the html for next and previous would be something like this; <a href="news.php?page=<?php echo $page+1 ?>">Next</a> Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824837 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 Sorry I still a little confused, can you clarify a little for me. Say my comment script is in comment.php and my main read page is page.php?id=#s script: <?php $page_id = "ID1"; ?> is inside of comment.php, which i needed the ID to have change from page.php?id=1 to page.php?id=2. say if page.php?id=1, then in comment.php, it should have ID1. and in page.php?id=2, comment.php should have ID2, without me changing anything in comment.php. and on page.php, i used : <div id="viewComment" style="display: block;"> <iframe style="height: 118px; width: 580px;" src="comment.php" name="ifrmComment" id="ifrmComment" scrolling="no" width="580" frameborder="0"></iframe> </div> to call upon comment.php Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824843 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 It would be easier to do this if you inluce comment.php, not put it in an iframe. There are many benefits of doing it that way, one being the ability of the included file to use the variables already loaded Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824846 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 The thing is that I have a code: <div class="tal"> <img src="http://image.vickizhao.net/style_guide/txt/txt_starhome_comment.gif" alt="" /> <img id="imgobj" src="http://image.vickizhao.net/style_guide/icn/icn_starhome_hidden.gif" onclick="openReply('http://image.vickizhao.net')" class="hand" alt="" /> </div> <p style="margin:5px;"></p> Which is used to hide and show the comment, but it must be in an iframe as the original coder make it that way and I think it would be a big mess trying to make it not iframe. So is there a way? or would i be better off creating a folder and put comment1.php comment2.php comment3.php and so on and use your first option, which to have the script to generate its ID by it page name? Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824849 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 You can pass the get global from page.php when calling the iframe; <?php if(!isset($_GET['page'])) { $page = 1; } else { $page = (int) $_GET['page']; } ?> <iframe style="height: 118px; width: 580px;" src="comment.php?page=<?php echo $page ?>" name="ifrmComment" id="ifrmComment" scrolling="no" width="580" frameborder="0"></iframe> Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824851 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 In comment.php, there is a code: <?php $page_id = "UniqueID"; ?> and no two UniqueID may be the same. You probably say this earlier but what can I do to make sure no two UniqueID are the same in comment.php? Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824856 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 I don't understand. Surely the page.php script gets it's own GET value, which needs to be passed to comment.php. So you don't need a unique ID, you need to pass the id. Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824858 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 sorry if i don't make sense, let me explain it in detailed. There are 2 pages: page.php?id=#s, which has many pages in it and it's the read page for my paragraph. comment.php?id=#s, which thank to you, i solved the puzzle of not having to create many comment pages and just use ?id. But inside of comment.php, off all the code in there, only one thing need to be changing from page to page so that no two id in in page_id are the same, and that is <?php $page_id = "THIS AND IT CAN BE ANYTHING, # OR LETTER"; ?> Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824862 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 If you just want to make a unique string you can used a guid, very easy in php5; $token = md5(uniqid(rand(), true)); Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824866 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 nvm, i think i finally solved the puzzle thank to you. Here is what i got: so if comment.php has id=RANDOM ID, say comment.php?id=1029 ,then i can use <?php if(!isset($_GET['page'])) { $page = 1; } else { $page = (int) $_GET['page']; } ?> inside of comment.php and in comment.php: <?php $page_id = "<?php echo $page ?>"; ?> than no two id in $page_id can be the same. Thank you soo much gevans Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824868 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 <?php $page_id = md5(uniqid(rand(), true)); ?> like this? Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824869 Share on other sites More sharing options...
gevans Posted May 3, 2009 Share Posted May 3, 2009 yea Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824870 Share on other sites More sharing options...
y2yang Posted May 3, 2009 Author Share Posted May 3, 2009 You're Perfecto gevans. Yet another hero saved my day. ;D ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/156648-solved-number-to-change-on-different-page/#findComment-824871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.