altafneva Posted February 11, 2014 Share Posted February 11, 2014 Hii..I had made a table in the database. And also had printed out the data...There are 20 episodes in a movie...And I had fetch and printed all the 20 episodes.Now I want to make those 20 lines clickable link and when user clicks on that link than it should perform some operation like in the thenewboston.org website when you click on Video & Tutorials Tab from the nav bar than it opens up all the topics. and when we click on for e.g. PHP VIDEOS than it takes to the particular page and than in the PHP Tutorials it shows a list of 200 videos and than when you click on any of the page than it fetch the data from database and than print the related data.So how should I make the dynamic links like http://thenewboston.org/watch.php?cat=11&number=21 ...And how should I write the operation in my php page which than performs the query and display it on that page... Any link referring to tutorial will work...Any Help would be appreciated. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 11, 2014 Share Posted February 11, 2014 Sorry, I'm not entirely sure I follow. Do you need help with creating the links? If so, what does your code which display the list of episodes look like so far? It might also be helpful to know what the database which contains the episode information looks like. Does it contain the necessary "cat" and "number" information for the links? Or do you already have the links created and you're just looking for help with using the "cat" and "number" variables? If so, are you familiar with $_GET? http://www.php.net/manual/en/reserved.variables.get.php Note that if you post code, please surround it with tags. It will make the code and your post easier to follow. Quote Link to comment Share on other sites More sharing options...
altafneva Posted February 11, 2014 Author Share Posted February 11, 2014 Sorry, I'm not entirely sure I follow. Do you need help with creating the links? If so, what does your code which display the list of episodes look like so far? It might also be helpful to know what the database which contains the episode information looks like. Does it contain the necessary "cat" and "number" information for the links? Or do you already have the links created and you're just looking for help with using the "cat" and "number" variables? If so, are you familiar with $_GET? http://www.php.net/manual/en/reserved.variables.get.php Note that if you post code, please surround it with tags. It will make the code and your post easier to follow. I am familiar with GET somewhat.... Here is my php code... <?php require 'connect.inc.php'; $query="SELECT * FROM `add_movie`"; if ($query_run=mysql_query($query)) { $i=1; while ($query_row=mysql_fetch_assoc($query_run)) { $movie_name=$query_row['movie_name']; $movie_desc=$query_row['movie_desc']; $movie_image_path=$query_row['movie_image_path']; echo ' <a href="movies_watch.php?movie='.$i.'"> <table class="movie_thumb"> <div class="selected_link"> <tr>'; echo '<td> <img src='.$movie_image_path.' </td>'; echo '<td> <h3>' .$movie_name. '</h3>'; echo '<br/> <p>' .$movie_desc. '</p></td>'; echo '<tr> </table> </a></div> <hr/>'; // Now where should i write the code for click event on a link. // Above you can see that I have created links. If there are 20 entries in the databse than 20 links would be created $i++; } } else { echo 'There was some error.'; } Now where I have to write the code and in what condition so when the user click on the 4th link than it should execute the 4th entry. Where to write GET method execution and executing Header() function.???? Quote Link to comment Share on other sites More sharing options...
rwhite35 Posted February 11, 2014 Share Posted February 11, 2014 (edited) Looking at your code, I think there might be a few other things to consider. Most important, what happens when you remove a movie from the list? The way you are "ID'ing" you movie isn't relevant to your movie list. Each movie should have its own unique id. Once you have done that, then creating links will be much simpler. And more flexible. Take another look at your program logic. But to answer your questions. If your movie has an ID, then you can simple create an anchor with that movies id. print '<a href="movie_watch.php?movie=$uniqueID" target="_blank"><img src="$movie_image_path"…>'; Edited February 11, 2014 by rwhite35 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 11, 2014 Share Posted February 11, 2014 Does your movie table have a primary key? If so, it's better to use an ID which directly relates to the movie information that the website should pull up. If your primary key is called "movie_id", for example, you could do something like: echo '<a href="movies_watch.php?movie='.$query_row['movie_id'].'">'; Also, have you tried validating the output? http://validator.w3.org/ Note that the <table> tag isn't supposed to go inside an <a> tag. Quote Link to comment Share on other sites More sharing options...
altafneva Posted February 11, 2014 Author Share Posted February 11, 2014 (edited) Sorry Guys for not able to explain my problem clearly. Actually I know how to create the links... What I don't know is that where to write the code for further process when the user clicks on the link. Can you please explain me with simple example. Lets assume that I have a table in the database which has 20 episodes of a particular movie stored into it. Now In the above code I had already fetch the data from database and applied the anchor tag to each. But now what to do..??? How to use GET method to call a particular link from among the 20 links..?? And how to redirect to that particular page..?? Please provide me the code with explanation.. Will Appreciate a lot... Thanks for the Help.. Edited February 11, 2014 by altafneva Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 11, 2014 Share Posted February 11, 2014 (edited) If you are using an ID which is specifically tied to the row containing the episode information, you just need to get the ID using $_GET and run a query like the following: $query = "SELECT * FROM `add_movie` WHERE id={$_GET['id']} LIMIT 1"; Edited February 11, 2014 by cyberRobot 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.