Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format output from mysql db as url link in a table? 1

Status
Not open for further replies.

phn737

Technical User
Nov 4, 2002
31
US
I am trying to use the script below to create a link to each user home directory on the webserver. The url will be an ip address follow by the user complete name (ex: from the mysql db. I am having problem outputting the name as a url link. How should I format the printf command to get the username as a url link? Or is there another way of doing this? Could some please help.

Thank you.

<html>
<body>
<?php
$db = mysql_connect(&quot;localhost&quot;, &quot;root&quot;);
mysql_select_db(&quot;testdb&quot;,$db);
$result = mysql_query(&quot;SELECT * FROM employees&quot;,$db);
if ($myrow = mysql_fetch_array($result)) {
echo &quot;<table border=1>\n&quot;;
echo &quot;<tr><td>Name</td><td>Position</td></tr>\n&quot;;
do {
printf(&quot;<tr><td>%s %s</td><td>%s</tr>\n&quot;, $myrow[&quot;first&quot;], $myrow[&quot;last&quot;], $myrow[&quot;address&quot;]);
} while ($myrow = mysql_fetch_array($result));
echo &quot;</table>\n&quot;;
} else {
echo &quot;Sorry, no records were found!&quot;;
}
?>
</body>
</html>
 
Something like

printf(&quot;<tr><td>%s %s</td><td><a href=\&quot;%s\&quot;>%s</a></tr>\n&quot;, $myrow[&quot;first&quot;], $myrow[&quot;last&quot;], $myrow[&quot;address&quot;], $myrow[&quot;address&quot;]);

should do it.


______________________________________________________________________
TANSTAAFL!
 
Thank you sleipnir214.
This is exactly what I wanted.
This will reference to the current location the script is in, I just need to put a static url in after the href= and put that in single quote, to reference to my desire url.

I really appreciate the time, effort, and your kindness that you and others provides to technical forums.

:)
 
One more thing.

Some of the output from the db is too long (datatype is text) and it is expanding the table column too wide. I want to limit it to approximately 2 inches. I tried putting the <td rowspan=5> put it is not working out for my.

How can I fix this?

Thank you
 
Using width=## inside the td element does seem to work.
Tried using nl2br, it is giving me this error:

Warning: wordwrap() expects parameter 2 to be long, string given in e:\htdocs\webmonkey\mylink.php on line 48

Is this because of the datatype of my variable? The variable is using datatype=text.

This is what I have in line 48:
nl2br(wordwrap(50,$myrow[&quot;description&quot;])),

For some reason I can not access the php.net site today, error: 10061 - Connection refused
Internet Security and Acceleration Server
 
Read the docs link on word wrap. I accidentally gave you the parameters to wordwrap in the wrong order. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top