|How to create a link out of document "Titles"? |
| 1:44 am on Oct 11, 2004 (gmt 0)|
Thanks for the great advice. I have another question. How would I turn the titles of my database news articles into links. I would like for the visitor to click the title, and be taken to the actual page the article is located? Can that be done?
Thanks in Advance,
// connect to the mysql server
mysql_connect("localhost","moot","ok") or die (mysql_error());
echo "Connected to Mysql<br/>";
// select the database
mysql_select_db("News_Articles") or die
echo "Connected to Database<br/>";
// insert data into ccds_news table
$sql = "INSERT INTO ccds_news(article_title, author_name, subject, date_created, content, EMAIL) VALUES('" . $_POST['article_title'] . "', '" . $_POST['author_name'] . "', '" . $_POST['subject'] . "', '" . $_POST['date_created'] . "', '" . $_POST['content'] . "', '" . $_POST['EMAIL'] . "' )";
// run the query
echo "DATA ENTERED!";
| 6:27 am on Oct 11, 2004 (gmt 0)|
I'm not quite sure what you're trying to do (it's early in the morning so i'm not quite with it). Perhaps you could tell us what pages these articles are displayed on, or is that what you are asking about?
| 7:48 am on Oct 11, 2004 (gmt 0)|
Obviously, you'll need echo and some knowledge of variables or arrays. Then, look at the 'parameters' your script is making in the urls - ht*p://mysite.com/index.php?this=whatever&that=whatever - parameters here being 'this' and 'that' - these produce elements of the array $_GET on the page that the link goes to - you'll want to figure out how to 'echo' out links that look like this with the proper parameters. If you don't have a link structure like this, you'll have to figure out what your link structure is, and produce url's according to that.
The php.net tutorial has a page on forms at [be2.php.net...] and you might want to get a book on paper too.
| 8:54 am on Oct 11, 2004 (gmt 0)|
Like mincklerstraat mentions, you`ll need to look into arrays and query strings. When you pull your data, you`ll need to loop through the entries and assign the article ID to a query string, ie: www.yoursite.com/articles.php?id=ID. Use mysql_fetch_array() to loop the entries.
When any link is clicked, you simply pull data based on the value of 'id' in the query string.
$query = "SELECT FROM table WHERE id = '" . $_GET['id'] . "' LIMIT 1";
//rest of code
I would suggest you follow the link that mincklerstraat has posted, it should point you in the right direction.
| 9:27 am on Oct 11, 2004 (gmt 0)|
are you talking about links like this:
for a story with the title: "freddie star ate my hamster"?
you need to google for 'search engine friendly URLs'. this article by sitepoint is a great starter: [sitepoint.com...] (although it might not work unless you have register_globals on in your php setting.) have a read and come back with questions.