#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    newbie alert!!!

    I have a table that users have entered their email & url addresses into. I want my query row to place the words "Email" and "Web page" in it but be linked to their mailto: and page addresses.

    I have it working but it also places "Email" and "Web Page" on rows that have no data entered by the user. These link to "mailto:" and the directory the viewing page is listed to. My desire is to leave these places blank.


    Hope this is not too confusing.

    stujo
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    14
    I will assume you are using a mysql_fetch_array to display the results,

    in the middle of your while statement you will want to use an if else check for making sure that the fields have a value
    print '<table>';
    while($row = mysql_fetch_array($result)) {
    if ($row["email"] != ""){
    $email = sprintf('<a href="mailto:%s">email</a>', $row["email"]);
    }
    if ($row["url"] != ""){
    $url = sprintf('<a href="%s">web site</a>', $row["url"]);
    }
    printf('<tr><td>%s</td><td>%s</td></tr>', $email, $url);
    }
    print '</table>';
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    Your suggest really makes sense ( I don't have a grasp on 'sprintf' though )

    I am getting the following error on the 'while' line ???

    Parse error: parse error, expecting `';'' on line 24

    Here is the section of code we are working on.

    if ($myrow = mysql_fetch_array($result))
    {
    echo "<table border=0 width=95% cellspacing=5>n";
    echo "<tr><td width=*></td><td width=15></td><td width=15></td><td width=90></td></tr>n";

    do {

    printf("<tr><td valign=bottom><BR>%s</td><td valign=bottom><a href='mailto:%s'>Email</a></td><td valign=bottom><a href='%s'>URL</td><td valign=bottom>%s</td></tr>n", $myrow["ad"], $myrow["email"], $myrow["url"], $myrow["phone"]);

    }

    while($row = mysql_fetch_array($result)) {
    if ($row["email"] != "")
    {
    $email = sprintf('<a href="mailto:%s">email</a>', $row["email"]);
    }
    if ($row["url"] != "")
    {
    $url = sprintf('<a href="%s">web site</a>', $row["url"]);
    }
    }

    echo "</table>n";

    } else {

    Thanks for the help!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    Two problems:

    change

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $email = sprintf('<a href="mailto:%s">email</a>', $row["email"]);
    [/code]

    to

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $email = sprintf("<a href="mailto:%s">email</a>", $row["email"]);
    [/code]

    and

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $url = sprintf('<a href="%s">web site</a>', $row["url"]);
    [/code]

    to

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $url = sprintf("<a href="%s">web site</a>", $row["url"]);
    [/code]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    Nope. Still gets caught up with the same error on the 'while' line.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    I noticed in the 'while' line I have

    $row

    and changed it to

    $myrow

    didn't get past the error looking for ;'"

    which way is right $row or $myrow ?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    SUCCESS !!!!!!!!!!!!!!!!

    Initial results look good but to tired to fully test.

    freddydoesphp was close

    I moved the sprintf() stuff up before I printed the table. Also had to use brute force and make $email and $url = "".

    Thanks for all the help people! I can finally sleep!
    ===========================================
    if ($myrow = mysql_fetch_array($result))
    {
    echo "<table border=0 width=95% cellspacing=10>n";
    echo "<tr><td width=*></td><td width=15></td><td width=50></td><td width=90></td></tr>n";

    do {

    if ($myrow["email"] != "")
    {
    $email = sprintf("<a href="mailto:%s">Email</a>", $myrow["email"]);
    }else
    {$email = "";
    }
    if ($myrow["url"] != "")
    {
    $url = sprintf("<a href="%s">Web Site</a>", $myrow["url"]);
    }else
    {$url = "";
    }

    printf("<tr><td valign=bottom><BR><BR>%s</td><td valign=bottom>$email</td><td valign=bottom>$url<td valign=bottom>%s</td></tr>n", $myrow["ad"], $myrow["phone"]);

    } while ($myrow = mysql_fetch_array($result));
    echo "</table>n";
    } else {
    echo "Sorry, no records were found!";
    }

Similar Threads

  1. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 04:45 AM
  2. posting query results to a php page
    By collegebloke in forum PHP Development
    Replies: 4
    Last Post: January 7th, 2004, 10:07 AM
  3. trying to create and populate table with query results
    By alexmasters in forum MySQL Help
    Replies: 1
    Last Post: January 5th, 2004, 10:37 AM
  4. modifying mysql query to refine results
    By jules00 in forum PHP Development
    Replies: 10
    Last Post: December 16th, 2003, 12:54 PM
  5. How to display a message if a query returns no results
    By SamKennedy in forum PHP Development
    Replies: 8
    Last Post: November 29th, 2003, 08:54 AM

IMN logo majestic logo threadwatch logo seochat tools logo