Jump to content

make links with url from sql but not print link for blank entries.


Recommended Posts

Thanks for the try on that. Looking back i see i didn't include all the info properly.

so here i try once more.

This is the current site:

http://sociology.berkeley.edu/index.php?page=faculty

 

As you can see the "Personal Page" link goes nowhere. The entry in the SQL table for this info is empty on most rows.

Currently only one row has data. That data is properly put into the link for Burawoy, so that the "personal site" link takes you there.

 

What i need to figure out is  the IF statement for the "$url" that is the "personal site" link on the page.

IF the url table entry is blank i want it to display nothing, no link at all. only show the "personal Site" link if the table entry for URL has data.

The url column in the table is "longtext"

 

 

below is the code for that page as it shows on the web today. this was all in place when I got here so i am learning as we go.

 

 

Thanks again for any help.

 

<?

require("abs_path.php");

require("mysql_connect.php");

if (!array_key_exists("search", $_GET)) $_GET["search"] = "regular";

 

if ($_GET["search"] == "regular") {

    $sql="select * from faculty ORDER BY LastName";

    $title = "Regular Faculty";

}

elseif ($_GET["search"] == "visiting") {

    $sql="select * from vfaculty ORDER BY LastName";

    $title = "Visiting Faculty";

}

elseif ($_GET["search"] == "emeritus") {

    $sql="select * from emfaculty ORDER BY LastName";

    $title = "Emeritus Faculty";

}

elseif ($_GET["search"] == "affiliated") {

    $sql="select * from affaculty ORDER BY LastName";

    $title = "Affiliated Faculty";

}

else

    die("invalid query; no such faculty type");

 

$result = mysql_query($sql);

$text = sprintf("

    <style type=\"text/css\">

    <!--

    td.faculty { font-size: small; }

    ul.interests { margin: 0; padding: 0; }

    ul.interests li { list-style-type: none; display: inline; font-size: small;}

    -->

    </style>

    <h2>%s</h2>

            <p>Alphabetical Listing</p>

        <table>

", $title);

 

while($rs = mysql_fetch_assoc($result))

{

  if ($rs["current"])

  {

    $pattern_str = <<<EOT

        <tr><td colspan="2"><hr style="border:0; background-color: #333366; height: 1px;"/></td></tr>

        <tr><td class="faculty" valign="top"><strong>%s, %s</strong><br /> %s<br />

            <font style="font-family: monospace;">%s</font><br />

                <a href="../faculty/%s/">Profile</a>    $url %s

 

$url <a href="$rs">Personal Site</a>

 

        </td>

            <td valign="top">

            <ul class="interests">%s</ul>

        </td>

        </tr>

EOT;

 

    $arrInterests = preg_split("/[,;]/", $rs["Interests"]);

 

    $strInterests = "<ul>";

 

    /*****************/

    /** This does all but the last in the loop.

        Why the special case?  Because didn't want to put

        a spare if statement in every iteration of the loop. **/

 

    $numInterests = count($arrInterests);

    $separator = ", ";

    for ($i = 0; $i < $numInterests - 1; $i++) {

        $strInterests .= "<li>" . $arrInterests[$i] . $separator . "</li>";

    }

    $separator = "";

    $strInterests .= "<li>" . $arrInterests[$numInterests - 1] . $separator . "</li>";

    /*****************/

 

    $strInterests .= "</ul>";

 

    $last_name_lowercase = strtolower($rs["LastName"]);

    $rel_path = sprintf("faculty/%s/cv.pdf", $last_name_lowercase);

    $path_to_possible_cv = sprintf($abs_path . $rel_path);

    if (file_exists($path_to_possible_cv)) {

        $cv_str = sprintf("  <a href=\"%s\">CV</a>  ", $rel_path);

    }

    else {

        $cv_str = "";

    }

 

 

 

 

 

 

      $output = sprintf($pattern_str, $rs["LastName"], $rs["FirstName"], $rs["Title"], $rs["email"], $rs["LastName"], $cv_str, $strInterests);

      $search = array("?", "@");

      $replace = array(" ", " AT ");

      $output = str_replace($search, $replace, $output);

      $text = $text . $output;

 

  }

 

}

    $text = $text . "</table>";

$page->setTextBody($text);

$page->pageTitle = "Faculty";

require("facultytoc.php");

?>

 

 

I am sure this is a rather basic thing for php and as i learn more i promise to ask less and answer more.

 

I see it is not all showing right in preview, I will try to get it here:

had to add the spaces to make it show right.

 

 

ok moved a step ahead on this.

 

if you look at the site now:

http://sociology.berkeley.edu/index.php?page=faculty

 

I got the only show a link if there is an entry in the table part down. Here was the code i worked out.

 

if ($rs["url"] > null) {

$strURL = "  <a href=$r s [ u r l ] > Personal Site < / a > ";

}

else

{ $strURL = "";

 

 

The odd looking spaces are so the code would print here and no turn into a link for this post.

 

So it mostly works.

 

problem i now have is that it moved the link one slot down in the table.

 

the one "personal site" showing shows one person lower in the table then it should.

the entire pages code can be seen in post 3 to this thread.

$url became $strURL but is otherwise just what you see there.

 

Thanks for any advice on this.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.