Help making a certain field into a hyperlink from an echoed MySQL table

05-11-06, 02:16 PM
|
|
Newbie Coder
|
|
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Help making a certain field into a hyperlink from an echoed MySQL table
Below is a truncated version of the MySQL table. The main focus is the title field. (I also have a question about the id field.)
Below is the PHP code I use to output the table's fields, minus the id field, into an HTML table for organized display on a web browser.
So, to my question. How could I hyperlink the movie titles to another page automatically? I'd like page to be named after the id; for example, Robin Hood: Prince of Thieves would hyperlink to 1.php, A Perfect World would hyperlink to 2.php, and Lolita would hyperlink to 3.php. The only way I've thought of doing so is by inputting the actual HTML code into the title field.
This way seems impractical, and ORDER BY title won't function as intended anymore. Also, is it possible to have the id start at 0001 instead of 1? When I input the zeros, they vanish after I've submitted.
|

05-11-06, 02:51 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
For your last question, you would need to change the definition of your ID field to include - INT(4) ZEROFILL
You can build and echo the title as a link, using the id as the page number, but it would require eliminating the foreach loop. Since, you only have three fields this might not be that bad. I notice too that your posted code does not include an opening TABLE tag.
However, since naming and storage schemes often need to change (perhaps you find that after there are a few hundred files that you want to divide them up into sub folders or that using the ID makes it too hard to keep track of which file goes with which title), I recommend adding a column to your table that would hold the link. In this way the link can be whatever you want.
For this second scheme, you would still order the results based on the title field, but you would SELECT the link field and echo it out. The link field could be saved fully formed (which would repeat the title name) or you can build the link that you echo in the table from the link field (which would only contain the link address) and the title (which would provide the link display name.)
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

05-11-06, 07:54 PM
|
|
Newbie Coder
|
|
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK, here is what I have now.
I've almost got it! Two questions: How do I append .php after ".$row[id].", and how do I encapsulate the two between double quotations?
Here is an example of what the above code outputs.
Here is an example of what I want.
|

05-11-06, 09:43 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You are essentially building a string. The following will work -
To get a double-quote within the string, put the \ to escape it. The .php is just part of the string.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

05-11-06, 10:03 PM
|
|
Newbie Coder
|
|
Join Date: Jul 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you, mab. You've helped me a great deal. 
|

05-11-06, 10:20 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by cynebald
Thank you, mab. You've helped me a great deal. 
|
Thanks for saying so. It is a pleasure to help someone who knows their code, is only missing a little piece to make it all work, and can take an idea and incorporate it into what they already have  .
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|