Can I apply urls stored in mysql as links in dreamweaver?

Hello experts, I am working on a website in Dreamweaver CS4 using wamp/

I have a dynamic table of data from mysql relating to news articles that the website's users may be interested in viewing. I would like users to be able to click on the row or a word or two such as 'read more' and navigate to the third party website where they can view the full article.

The columns I have within the database are:

news_id (primary)
news_section (I would like to separate the news into four categories)
news_date (the date the article was written)
news_source (the site that published the article)
news_headline
news_intro (the first paragraph)
news_link (the URL I wish to link to)

How do I go about using the URL that is being held and applying it to the either the entire row or to the text 'read more'.

As I said, this is all new to me.

Your help would be appreciated"
TimDuntonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Hi, Tim.  I'm not sure I can help with the Dreamweaver part of this, but I can show you the general guidance that would get this information from the DB into the HTML.
<?php // RAY_mysql_example.php
error_reporting(E_ALL);
 
// IMPORTANT PAGES FROM THE MANUALS
// MAN PAGE: http://us2.php.net/manual/en/ref.mysql.php
// MAN PAGE: http://us2.php.net/manual/en/mysql.installation.php
 
 
// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";
 
// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB CONNECTION: ";
   echo "<br/> $errmsg <br/>";
}
 
// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>NO DB SELECTION: ";
   echo "<br/> $errmsg <br/>";
   die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES
 
 
 
// CREATING AND SENDING A SELECT QUERY AND TESTING THE RESULTS
// MAN PAGE:http://us2.php.net/manual/en/function.mysql-query.php
// APPLY THE APPROPRIATE WHERE AND LIMIT CLAUSES TO THIS QUERY
$sql = "SELECT news_headline, news_link FROM my_table";
$res = mysql_query($sql);
 
// IF mysql_query() RETURNS FALSE, GET THE ERROR REASONS
if (!$res)
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "<br/>QUERY FAIL: ";
   echo "<br/>$sql <br/>";
   die($errmsg);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESOURCE-ID IN $res SO WE CAN NOW USE $res IN OTHER MYSQL FUNCTIONS
 
 
 
// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
// MAN PAGE: http://us2.php.net/manual/en/function.mysql-num-rows.php
$num = mysql_num_rows($res);
if (!$num)
{
   echo "<br/>QUERY FOUND NO DATA: ";
   echo "<br/>$sql <br/>";
}
else
{
   echo "<br/>QUERY FOUND $num ROWS OF DATA ";
   echo "<br/>$sql <br/>";
}
 
 
 
// ITERATE OVER THE QUERY RESULTS SET
while ($row = mysql_fetch_assoc($res))
{
 
// INJECT COLUMN NAMES AND VALUES INTO MY NAMESPACE
   extract($row);
 
// CREATE THE LINKS
   echo "<br/><a target=\"news\" href=\"$news_link\">$news_headline</a\n";
}

Open in new window

0
TimDuntonAuthor Commented:
Hi Ray, thanks for taking the time to respond...

I already have the database connection set up and the queries are working fine. I can also display the data.

What I'm struggling with is this:

1) At the moment the URLs are stored in a varchar field in the database and so when they are displayed they are simply text. Is this ok?

2) I don't actually want to display the URL, rather apply the URL as a link to one/all of the fields in the row. So for example, a user can look at the headline, read the intro and if he/she wants to read more, can simply click and be directed to the original article (without having to view or click on the actual URL)

As I mentioned I really am very new to this, your help is appreciated.

Thanks
   
0
Jason C. LevineNo oneCommented:
Hi Tim,

If I read your question correctly, all you need to do is echo the URL being held in the database into an <a> construct in your HMTL:

<a href="<?php echo $row_YourRecordSet['news_link'] ?>">Read more</a>

The easiest way to build the link above is to type "Read more" in Design View then select it.  In the Properties Panel, click the lightning bolt icon next to the link box to map the link to the database field.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Ray PaseurCommented:
Hi, Tim.  See line 79 in the code snippet above.  That would (almost) do what you suggest, if you fix my typo!.
echo "<br/><a target=\"news\" href=\"$news_link\">$news_headline</a>\n";

Open in new window

0
TimDuntonAuthor Commented:
Thanks guys, I'm going to have a little play around and see where I'm at. I'll get back to you asap
0
TimDuntonAuthor Commented:
Thanks so much guys. I almost feel guilty using experts exchange, the advice is so valuable and succinct. I promise however that I spend hours trying to work things out for myself before asking a question here.

I have no training and have really thrown myself in at the deep end so I can only say thanks again, I'd be pulling my hair out by now if it wasn't this site and the experts who share their knowledge. Be lucky!
0
Jason C. LevineNo oneCommented:
Thanks for the kind words, Tim.

A bit of explanation between Ray's answer and mine.  Ray is a REAL php coder and I fake it convincingly with the help of Dreamweaver.  In the grand scheme of things, Ray's answer is actually better as it shows you the steps to you will need in order to really learn how PHP does things while my answer addresses the Dreamweaver interface more than it does PHP code.

Good luck with your site and feel free to keep asking questions of us.  Don't feel guilty :)
0
Ray PaseurCommented:
Tim: Thanks for the points; it's a good question.  

Let me echo what jason1178 says: One of the best attributes in a programmer is laziness!  Think about it... Lazy programmers rely on examples and advice.  Lazy programmers avoid repeating their mistakes and save time debugging, etc.  Personally I have found EE to be a great resource for the lazy pursuit of my programming goals.  One should never feel guilty about this sort of thing.

But if you want to put a little work into your PHP education, consider getting this excellent book.
http://www.sitepoint.com/books/phpmysql1/

Best regards, ~Ray
0
Jason C. LevineNo oneCommented:
>> One of the best attributes in a programmer is laziness!

Oddly enough I was just telling my database dev that he needs to get lazier instead of constantly trying to reinvent the wheel :)
0
TimDuntonAuthor Commented:
Sorry chaps, only just noticed your final comments. I appreciate the pointers and I'll definitely take a look at the book. Thanks Ray & Jason, keep up the good work!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.