Lambneck Posted April 10, 2008 Share Posted April 10, 2008 Hello, How can I echo a mysql row as a link? for example, I tried the following but it didnt work: while($row = mysql_fetch_array($result)) { echo '<a href=www.mysite.com/display.php">'$row['col_4']'</a>'; echo "<br />"; } mysql_free_result($result); ?> any suggestions? ??? Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/ Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 you are using a literal string, you have two options: concatenate echo '<a href="www.mysite.com/display.php">'.$row['col_4'].'</a>'; or inline echo "<a href='www.mysite.com/display.php'>'$row['col_4']'</a>"; make sure any quotes are escaped, eg: echo "<a href=\"www.mysite.com/display.php\">'$row['col_4']'</a>"; hope thsi helps, Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513559 Share on other sites More sharing options...
blackcell Posted April 10, 2008 Share Posted April 10, 2008 To bounce off this and save a topic, what does literal really mean? Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513561 Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 literal means it does not parse variables or newlines etc in string declerations... example echo "this line\nis broken"; would output this line is broken -- whereas echo 'this line\nis broken"; would 'literally' output this line \nis broken Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513564 Share on other sites More sharing options...
Lambneck Posted April 10, 2008 Author Share Posted April 10, 2008 hmm, it still didn't work. this is the code as it is now: if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT col_4 FROM {$table}"); if (!$result) { die("Query to show fields from table failed:".mysql_error()); } while($row = mysql_fetch_array($result)) { echo "<a href=\"www.mysite.com/display.php\">'$row['col_4']'</a>"; echo "<br />"; } mysql_free_result($result); Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513572 Share on other sites More sharing options...
zenag Posted April 10, 2008 Share Posted April 10, 2008 can u make a try at this.... echo "<a href=\"www.mysite.com/display.php\">'$row[col_4]'</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513579 Share on other sites More sharing options...
Lambneck Posted April 10, 2008 Author Share Posted April 10, 2008 Hey thanks Zenag it worked! Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513585 Share on other sites More sharing options...
blackcell Posted April 10, 2008 Share Posted April 10, 2008 Lambneck, what you have to watch for in php is the way you use double and single quotes together. Double quotes will override everything where singles can be used within double. So I always try to use doubles on everything so if the need arises for singles I can easily add them in without thinking of escaping things. I don't know if this is proper or not but it is the style I have gotten used to. Quote Link to comment https://forums.phpfreaks.com/topic/100420-solved-echo-link/#findComment-513791 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.