mark103 Posted January 18, 2012 Share Posted January 18, 2012 Hi all, I'm recent working on my php to extract some data from mysql database. Is it possible to output the database data into <a href> turn to the hyperlink instead of using http://mysite.freesite.com/mydatalink.com to this http://mydatalink.com? The script I have made so far is doing something wrong and I can't be able to find the solution. here's the current code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />', $errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT id, links FROM mydatalist WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="' . $row["links"] . '">Link</a> </td>'; } } } } ?> I don't want to adding an <a href> into the first echo statement, because I am stored the links in the database which you can see that I am using ['links']. I need to ouput the data from the db to turn into hyperlink. If anyone could assist with this I'd be very grateful! Thanks, Mark Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/ Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 So what is this doing or not doing that isn't expected? It looks okay to me. Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308744 Share on other sites More sharing options...
mark103 Posted January 18, 2012 Author Share Posted January 18, 2012 it extract the data that I stored in the database and it have output the data into the hyperlink to turn into this http://mysite.freesite.com/mydatalink.com. It's doing it wrong which I want the data to turn to the output hyperlink like this http://whateveristoredinthedb. Do you know how to do this and if i need to make the change? Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308747 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 What do the links that are stored in the database actually look like? Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308748 Share on other sites More sharing options...
mark103 Posted January 18, 2012 Author Share Posted January 18, 2012 It looks like this: whateveristoredinthedb. It just the data that I stored in the db cells. I hope you get this Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308749 Share on other sites More sharing options...
bspace Posted January 18, 2012 Share Posted January 18, 2012 you probably need to echo the http:// bit try echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td>'; also in this html, you have a paragraph id="images" as this is in a loop then presumably you may get more than one id of the same name id should be unique, use class="images" Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308752 Share on other sites More sharing options...
mark103 Posted January 18, 2012 Author Share Posted January 18, 2012 thank you very much, problem solved! Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1308761 Share on other sites More sharing options...
Pikachu2000 Posted January 18, 2012 Share Posted January 18, 2012 thank you very much, problem solved! There's a "TOPIC SOLVED" button for that. Quote Link to comment https://forums.phpfreaks.com/topic/255257-how-to-output-the-db-data-to-turn-into-hyperlinks/#findComment-1309068 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.