soc86 Posted September 12, 2011 Share Posted September 12, 2011 I am having more trouble with my code, please see the error below when loading my browser: Here is my blog Fatal error: Function name must be a string in W:\www\blog\index.php on line 14 My code is: <?php mysql_connect ("localhost", "root", "gwalia"); mysql_select_db("blog"); ?> <html> <head> <title>Show My Blog</title> </head> <body> Here is my blog<hr/> <?php $sql = mysql_query("SELECT * FROM blogdata ORDER BY id DESC"); While($row = mysql_fetch_array($sql)){ $title = $row('title'); $content = $row('content'); $category = $row('category'); ?> <table border='1'> <tr><td><?php echo $title; ?></td><td><?php echo $category; ?></td></tr> <tr><td colspan='2'><?php echo $content; ?></td><td></tr> </table> <?php } ?> </body> </html> Line 14 is '$title = $row('title');'. But i do not know what is wrong with my code, help please? Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/ Share on other sites More sharing options...
AyKay47 Posted September 12, 2011 Share Posted September 12, 2011 you want to use square brackets.. [] not parenthesis.. $title = $row['title']; Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268465 Share on other sites More sharing options...
cunoodle2 Posted September 12, 2011 Share Posted September 12, 2011 AyKay is correct. I also see an issue where you are setting a variable.... $title = $row['title']; And then just echoing it later. <?php echo $title; ?> Unless you are modifying the variable for some reason you are just bring up memory. To be more efficient just REMOVE this line.. $title = $row['title']; And in your echo statement just do this.. <?php echo $row['title']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268467 Share on other sites More sharing options...
requinix Posted September 12, 2011 Share Posted September 12, 2011 Unless you are modifying the variable for some reason you are just bring up memory. For a string value it's a negligible amount. If the coder has an easier time dealing with a second variable (which any decent IDE's intellisense would discover) then it's definitely in his/her favor to use it. Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268477 Share on other sites More sharing options...
AyKay47 Posted September 13, 2011 Share Posted September 13, 2011 I always set indexed values to variables.. makes for cleaner code.. the memory usage there is insignificant as requinix stated Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268672 Share on other sites More sharing options...
Pandemikk Posted September 13, 2011 Share Posted September 13, 2011 Funny. I always keep them in an array. Seems more logical to me. To each his own, Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268819 Share on other sites More sharing options...
AyKay47 Posted September 13, 2011 Share Posted September 13, 2011 Funny. I always keep them in an array. Seems more logical to me. To each his own, well ive found that assigning the value to a variable avoids annoying concatenation issues etc.. Quote Link to comment https://forums.phpfreaks.com/topic/246988-fatal-error-function-name-must-be-a-string-in-wwwwblogindexphp-on-line-14/#findComment-1268831 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.