PvtStash Posted October 26, 2007 Share Posted October 26, 2007 This may be in the docs somewhere, but lots of reading later and i have not yet seen it. If you can please help. here is the page http://sociology.berkeley.edu/index.php?page=faculty&search=regular there is a column called "url" here is the current code in use to make the "personal site" link. <a href="$rs">Personal Site</a> However most enrties in the column are blank and the page is created with a visible link that goes nowhere. I want to only see/create the link if a table entry exists. I am quite new to this so big learning curve for me here. thanks in advance for nay help or even just a link to the proper tutorial for this would be great. Quote Link to comment https://forums.phpfreaks.com/topic/74920-make-links-with-url-from-sql-but-not-print-link-for-blank-entries/ Share on other sites More sharing options...
marcus Posted October 26, 2007 Share Posted October 26, 2007 $sql = "SELECT * FROM `table` WHERE `this`='that'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0){ echo "Row exists"; }else { echo "Row does not exist"; } Quote Link to comment https://forums.phpfreaks.com/topic/74920-make-links-with-url-from-sql-but-not-print-link-for-blank-entries/#findComment-378823 Share on other sites More sharing options...
PvtStash Posted October 29, 2007 Author Share Posted October 29, 2007 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: $ u r l < a h r e f = " $ r s [ u r l ] " > Personal Site < / a > had to add the spaces to make it show right. Quote Link to comment https://forums.phpfreaks.com/topic/74920-make-links-with-url-from-sql-but-not-print-link-for-blank-entries/#findComment-380482 Share on other sites More sharing options...
PvtStash Posted October 30, 2007 Author Share Posted October 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74920-make-links-with-url-from-sql-but-not-print-link-for-blank-entries/#findComment-381355 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.