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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying url from db (newbie question)

Status
Not open for further replies.

Herminio

Technical User
May 10, 2002
189
0
0
PT
I'm a real newbie on PHP, but i want to know as much as i can, so here's my first problem(it wont be the last, i assure you)

I have this script:

Code:
<?php

			$db = mysql_connect("localhost", "********", "*********");

			mysql_select_db("guestbook",$db);

			$result = mysql_query("SELECT * FROM guestbook",$db);

			printf("Name: %s<br>\n", mysql_result($result,0,"NAME"));

			printf("Location: %s<br>\n", mysql_result($result,0,"LOCATION"));

			printf("Email: %s<br>\n", mysql_result($result,0,"EMAIL"));

			printf("Homepage: %s<br>\n", mysql_result($result,0,"URL"));

			printf("Comentário: %s<br>\n", mysql_result($result,0,"COMMENTS"));

		?>

This is the result:

Name: Herminio
Location: Porto
Email: <my email>
Homepage: <my site>
Comentário: Testando.

i want the text after homepage to show as link but i cant manage how to do that.

Please help me.

Thanks in Advance
 
How about:
Code:
            printf("Homepage: <a href='%s'>%s</a><br>\n", mysql_result($result,0,"URL"));
 
Warning: printf() [function.printf]: Too few arguments in dbteste.php on line 18

line 18 --> printf("Homepage: <a href='%s'>%s</a><br>\n", mysql_result($result,0,"URL"));
 
I would get away from using the mysql_result() function and use mysql_fetch_assoc() instead.

Code:
<?php
   $tmp = array();
            $db = mysql_connect("localhost", "********", "*********");
            mysql_select_db("guestbook",$db);
            $result = mysql_query("SELECT * FROM guestbook",$db);
   $row = mysql_fetch_assoc($result);
   $tmp[] = 'Name: ' . $row['name'];
   $tmp[] = 'Location: ' . $row['location'];
   $tmp[] = 'Email: ' . $row['email'];
   $tmp[] = 'Homepage : <a href="' . $row['url'] . '">' . $row['url'] . '</a>';
   $tmp[] = 'Comments: ' . $row['COMMENTS'];
   echo implode("<br>\n",$tmp)."<br>\n";
        ?>

I think it makes the code easier to understand and there's also less typing.

Ken
 
Thanks, that worked fine!

I'll see if i follow your sugestion and start using those alternatives.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top