Jump to content

Recommended Posts

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

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/224859-how-to-use-hyperlinks-in-a-statement/
Share on other sites

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);
?>

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

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)

$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.

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 ?

 

 

 

 

...

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)  :D

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.