shenagsandnags Posted January 18, 2011 Share Posted January 18, 2011 Im working on a movie database and im sure i can figure out how to insert a link into a table but i cannot figure out how to turn the movie titles themselves into the link when creating a statement. Say my table looks as this Title | Category | URL -------------------------------------------------------------------------- Titanic | Drama | Http://www.imdb.com/titanic So when i create my statement i want the actual title itself to be the hyperlink. get what im saying ? In my statement results i want it to look like: Titanic | Drama Avatar | Drama etc. (With Titanic and Avatar being the link) and not like: Titanic | Drama Http://www.imdb.com/titanic Avatar | Drama Http://www.imdb.com/avatar etc.. Im still working on fully understanding all this so if i sound like a idiot just bear with me Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 18, 2011 Share Posted January 18, 2011 Perhaps start with the definition for a link - http://w3schools.com/html/html_links.asp You put the URL into the url portion of the tag and you put the text into the Link text portion of the tag. Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161437 Share on other sites More sharing options...
dsjoes Posted January 18, 2011 Share Posted January 18, 2011 something like this click to see example http://scripttest.freeiz.com/ code <?php $con = mysql_connect("HOST","USERNAME","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DATABASENAME", $con); $result = mysql_query("SELECT * FROM TABLENAME ORDER BY Title"); echo "<table border='1'> <tr> <th>Title</th> <th>Category</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td width='100'><a href='".$row['Link']."'>" . $row['Title'] . "</a></td>"; echo "<td width='150'>" . $row['Category'] . "</td>"; } echo "</table>"; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161486 Share on other sites More sharing options...
shenagsandnags Posted January 19, 2011 Author Share Posted January 19, 2011 other then just having the link open in a new window or in a left frame (haven't decided yet) thats pretty much exactly what i was looking for. im actually using 2 tables for my DB and still need to write out a statement but yea, i didnt know how to make my titles links like that Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161791 Share on other sites More sharing options...
shenagsandnags Posted January 19, 2011 Author Share Posted January 19, 2011 Ok now a much easier question then, i just created a simple html form just as the scipt above (minus showing the results on the same page) but i need a drop menu instead of a text box that will pull all the categories thats listed in the categories table (which just holds ID and Category name) Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161830 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 $get_option_query = 'SELECT id, name FROM catagory ORDER BY id'; $result_set=mysql_query($get_option_query) or die (An error has occured retrieving the information from the database : '.mysql_error()); echo '<select name="cat_choice">' while ($row = mysql_fetch_assoc($result_set){ echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; } echo '</select>'; Untested, but something like that should get you what you want. Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161872 Share on other sites More sharing options...
shenagsandnags Posted January 19, 2011 Author Share Posted January 19, 2011 ok but with all this will this still allow me to group my results in multiple tables ? see all this has been real confusing to me because i have been using MS Access for some time now. in access all i had to do was create a simple query and then use a report wizard which allowed me to group my results. what i mean is, you see how the script above retrieved the movies but it showed the results in 1 table: Titanic | Drama Avatar | Drama with ms access i had it showing results in multiple tables and each table was a category with a listing of titles related like: -Drama- Avatar Titanic -Comedy- Friday Up in smoke its gone now but i think i used something like : Select Movies.title, Movies.[Category] From Movies Where Movies.[Category]=Drama ??? i also had another table called Categories which it only had ID and Category name. would it be that hard to do this within mysql/php ? Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1161948 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2011 Share Posted January 19, 2011 ... i have been using MS Access for some time now ... I'm sure there are clinics out there that can help with that (at least there should be) would it be that hard to do this within mysql/php ? No, it's fairly easy, you just need to forget any access psudo-SQL you may have picked up and focus on the language that you want to use. To format things they way you want you'll need to learn how to format tables using html as well. Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1162034 Share on other sites More sharing options...
shenagsandnags Posted January 20, 2011 Author Share Posted January 20, 2011 lol.. yessss i do know some html and i plan on focusing on php/mysql fully but i atleast have to part time with MS untill i can switch completely over. meanwhile, i have been going over s--t loads of tutorials for php/mysql and i would have thought that i would have figured this one out on my own after about literally the 5th time but im still in the dark somehow. i thought maybe creating virtual tables with VIEW is what i would need to do but after reading surely there has to be a more simple method especially if i might be adding or moving around my Categories aka tables. Quote Link to comment https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/#findComment-1162418 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.