rhodesa Posted May 15, 2008 Share Posted May 15, 2008 php will never wait for input unless you are using it via the command line. isset() is simply a test to see if something 'is set': <?php if(isset($var)) echo '$var is set'; else echo $var is not set'; $var = 'foobar'; if(isset($var)) echo '$var is set'; else echo $var is not set'; ?> $var is not set $var is set in the code i sent before, that if statement is checking to see if 'gid' is a valid array key inside the array $_GET. if it's not, that means gid is not in the url, and therefore no gallery has been selected Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 16, 2008 Author Share Posted May 16, 2008 Thank you. Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 16, 2008 Author Share Posted May 16, 2008 Now can I make this test in between the <title> tags so that I can obtain the random number and display it in the window title bar ? Also I dont see why we are testing here. When the page is loading , obviously he doesnt immediately make a gallery selection , so can't we just randomly pick one gallery and display it to him? Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 16, 2008 Author Share Posted May 16, 2008 Also , one thing I don't understand is , how does the whole think work ? Take a scenario. When I choose to view gallery1 , the file gallery1.txt is opened , and the contents(image links) read off and images displayed.Now at exactly the same time , lets assume a guy in the US chooses the same gallery for viewing.Now since the file is already open , how does PHP re-open it once again ? Won't it result in an error ? And what happens when people open two different galleries simultaneously ? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 16, 2008 Share Posted May 16, 2008 If you want the Title to be reflective of the random gallery, just move the code that determines the gallery to the top of the page. Then, when you print the title, you will be access that information: <?php //This is shorthand for if/else. Syntax: (test) ? true : false //So if (isset($_GET['gid'])) is true, $gid will be set to $_GET['gid'], false it will do the rand() $gid = (isset($_GET['gid'])) ? $_GET['gid'] : rand(1,3); ?> <html> <head> <title>Gallery <?php echo $gid;?></title> </head> <body> <?php $file = "gallery{$gid}.txt"; //Update to use $gid echo '<table border="2" style="margin:auto;">'; foreach(file($file) as $n => $line){ echo '<tr><td style="text-align:center;"><b>Image : '.($i + 1).'</b></td></tr>'; echo '<tr><td style="text-align:center;"><img src="'.$line.'"></td></tr>'; } echo "</table>"; ?> </body> </html> PHP starting to make sense yet? Every time you load a page, it will spawn an independent PHP process. Each process will have it's own file handle when opening/reading a gallery file. Multiple processes can read the same gallery file at the same time because it's just reading. Only when you get into writing a file do you have to worry about multiple people editing at the same time. Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 17, 2008 Author Share Posted May 17, 2008 Thanks for all the clarifications. I do recognise the C ternary operator. I was progressing well with php , learning it on my own when suddenly this isset() confused me and made me think it was an event handler of some sort.Thats why started asking too many questions for a good C programmer. Plus you know the fact that the environment is different , it is running on a webserver and there are security issues to be thought of. Hence the profusion of questions. Thanks for answering them patiently. Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 17, 2008 Author Share Posted May 17, 2008 Now I believe I can just had javascript code where ever I want in the script right ? I am talking about code from advertisers like Google adsense and visitor analysis code from statcounter. Quote Link to comment Share on other sites More sharing options...
harishkumar09 Posted May 28, 2008 Author Share Posted May 28, 2008 OK now , I have included javascript and tested it and found out that everything is working fine. Now I want a rating system.I want people to rate my gallery.I have put radio buttons to do it. But here obviously , many people will be writing into the same file "rateN.txt" where N is the gallery number.How do I handle it ? And also I want to display the current rating for a gallery.I will have to read the list of rating numbers from the file and average them and display it.In other words the file will be read by me and written to by so many people simultaneously.How do I get it done ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.