Hi All

I am having a bit fo an issue with an if/else statement inside a while statement. Basically there are two while statements. one to retrieve a distinct value, the second to list all links associated to that distinct value.

I am trying to build a favicon fetcher to display beside each link. I can do this part, but need to have a "no favicon" image displayed if the site does not have one, or it is placed somewhere other than the root of the domain.

i looked up if statements inside while statements but keep getting unexpected { errors.

is there anyone here who can see what i am doing wrong?

TIA

function links ()
{
//Select the distinctive CATEGORY titles from the CATEGORIES table
$sqlcat = 'SELECT DISTINCT category FROM ex_links ORDER BY category ASC';
$resultcat = mysql_query($sqlcat) or die('There are currently no links in the database.');
while ($rowcat = mysql_fetch_assoc($resultcat)){
//Begin the HTML formatting and output the CATEGORY title
echo "<div class='linkholder'>\n";
echo "<div class='linktitles'>";
echo "<h2>".$rowcat['category']."</a></h2>\n";
echo "</div>\n";
echo "<div id=\"navcontainer\">\n\n";
// Now we have the Category title, grab all links associated with that
// title and place them under the correct heading.
$sql = 'SELECT * FROM ex_links WHERE category="'.$rowcat['category'].'" ORDER BY title';
$result = mysql_query($sql) or die('There are currently no links in the database.');
while ($row = mysql_fetch_assoc($result)){
$id = $row["id"];
$url = $row["url"];
$title = $row["title"];
$ident = $row["id"];
$category = $row["category"];
$target = $row["target"];
echo "<div class=\"icoleft\"><a href=\"$url\" target=\"$target\"><img src=\"$url/favicon.ico\" height='16px' width='16px' /></a></div>\n";
echo "<div class=\"linkleft\"><a href=\"$url\" target=\"$target\">$title</a></div>\n";
echo "<div class=\"linkright\"><a href=\"admin/links_delete.php?identity=$id\"><img src=\"images/cancel.png\" /></a></div>\n";
echo "<div class=\"clear\"></div>\n";
}
?>
<script>
function dodeletelink( ) {
  new Ajax.Updater( 'linkmanager', 'admin/links_delete.php', { method: 'post', parameters: $('').serialize() } );
  $('').reset();
}
</script>
<?php
//End the HTML formatting for the links and categories
echo "</div>\n";
echo "</div>\n\n";
}
}
?>

this is the code i would like to have executed inside the second while statement

$filename = "$url/favicon.ico";

if (file_exists($filename)) {
    print "The file $filename exists";
} else {
    print "The file $filename does not exist";
}

I might suggest using some code formatting and maybe even an editor with syntax highlighting ... if this is the real script, it looks like maybe you missed actually closing your while loops ...

function links () {
  //Select the distinctive CATEGORY titles from the CATEGORIES table
  $sqlcat = 'SELECT DISTINCT category FROM ex_links ORDER BY category ASC';
  $resultcat = mysql_query($sqlcat) or die('There are currently no links in the database.');
  
  while ( $rowcat = mysql_fetch_assoc( $resultcat ) ) {
  
    //Begin the HTML formatting and output the CATEGORY title
    echo "<div class='linkholder'>\n";
    echo "<div class='linktitles'>";
    echo "<h2>".$rowcat['category']."</a></h2>\n";
    echo "</div>\n";
    echo "<div id=\"navcontainer\">\n\n";
    
    // Now we have the Category title, grab all links associated with that
    // title and place them under the correct heading.
    $sql = 'SELECT * FROM ex_links WHERE category="'.$rowcat['category'].'" ORDER BY title';
    $result = mysql_query($sql) or die('There are currently no links in the database.');
    
    while ( $row = mysql_fetch_assoc( $result ) ) {
      $id = $row["id"];
      $url = $row["url"];
      $title = $row["title"];
      $ident = $row["id"];
      $category = $row["category"];
      $target = $row["target"];
      echo "<div class=\"icoleft\"><a href=\"$url\" target=\"$target\"><img src=\"$url/favicon.ico\" height='16px' width='16px' /></a></div>\n";
      echo "<div class=\"linkleft\"><a href=\"$url\" target=\"$target\">$title</a></div>\n";
      echo "<div class=\"linkright\"><a href=\"admin/links_delete.php?identity=$id\"><img src=\"images/cancel.png\" /></a></div>\n";
      echo "<div class=\"clear\"></div>\n";
    } // THIS WAS MISSING
  } // THIS WAS MISSING
}
?>

I didn't really look at any of the code, I just noticed this problem -- hope it helps

This article has been dead for over six months. Start a new discussion instead.