Making an HTML link from PHP and MySQL
Results 1 to 5 of 5

Thread: Making an HTML link from PHP and MySQL

  1. #1
    Senior Member
    Join Date
    Jun 2000
    Posts
    65,357

    Making an HTML link from PHP and MySQL

    I was looking at some code for sellecting records from a database I was wondering, being new at PHP and MySQL if this is the way you would selected from the database is made into an html link.

    I'm not sure how to get the double quotes (") to print.



    if ($row = mysql_fetch_array($result)) {

    do {
    print ("<a href=/"");
    print $row["first_name"];
    print (".htm/" > ");
    print $row["first_name"];
    print " </a>"


    } while($row = mysql_fetch_array($result));

    } else {print "Sorry, no records were found!";}




    What I'm trying to get printed it something like this:

    <a href="Jason.htm"> Jason </a>

    where "Jason" would be taken from the database.


    Any help would be very much appreciated.

    Thanks

  2. #2
    Senior Member
    Join Date
    Jun 2000
    Posts
    65,357

    RE: Making an HTML link from PHP and MySQL

    if ($row = mysql_fetch_array($result)) {

    do {
    printf('<a href="%s.htm">%s</a>', $row["first_name"], $row["first_name"]);


    } while($row = mysql_fetch_array($result));

    } else {print "Sorry, no records were found!";}





  3. #3
    Senior Member
    Join Date
    Jun 2000
    Posts
    65,357

    RE: Making an HTML link from PHP and MySQL

    That is the %s in the link?

    (I'm really new at this...just a few days actuall.)

    Thanks for your help.
    Jaymz

  4. #4
    Senior Member
    Join Date
    Jun 2000
    Posts
    65,357

    RE: Making an HTML link from PHP and MySQL

    check the documentation on printf, the %s is just a plcaeholder for whatever arguments you supply at the end notice how there are two %s in the statement and two variaboles at the end.

  5. #5
    Senior Member
    Join Date
    Jun 2000
    Posts
    65,357

    RE: Making an HTML link from PHP and MySQL

    Cool...thanks so much for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •