| | |
if, else and while
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
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
this is the code i would like to have executed inside the second while statement
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
php Syntax (Toggle Plain Text)
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
php Syntax (Toggle Plain Text)
$filename = "$url/favicon.ico"; if (file_exists($filename)) { print "The file $filename exists"; } else { print "The file $filename does not exist"; }
Last edited by soddengecko; Sep 4th, 2008 at 7:48 pm.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
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 ...
I didn't really look at any of the code, I just noticed this problem -- hope it helps
php Syntax (Toggle Plain Text)
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
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Personal Account Page
- Next Thread: Serching an excel sheet?
| Thread Tools | Search this Thread |
.htaccess ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google headmethod href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu mlm mod_rewrite multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validation validator variable video web xml youtube





