Dakafall Posted June 29, 2010 Share Posted June 29, 2010 Hey all! Im trying to increase my skills in PHP and I am trying to code a menu in php that will fill with information gathered from a mysql database. I know how to make the table, but I am trying to write the functions to use and I cant seem to write the functions correctly. If you guys could help that would be awesome! Here is my code : <?php //*** Start Session ***\\ session_start(); //*** Variables For MySQL Connection ***\\ $db_user = "root"; $db_pwd = ""; $db = "project"; //*** Variables ***\\ $about = 'about'; // about table $services = 'services'; // services table $support = 'support'; // support table //*** Functions ***\\ function mysqlConnect($db_user, $db_pwd, $db) { $link = mysql_connect( "localhost", "$db_user", "$db_pwd"); // connects to mysql @mysql_select_db( $db ); // selects the database } function aboutMenu($about, $aboutResult) { $aboutResult = mysql_query("SELECT * FROM ($about)"); // selects about table $aboutFields_num = mysql_num_fields($aboutResult); // grabs number of fields from about table } function servicesMenu($services, $servicesResult) { $servicesResult = mysql_query("SELECT * FROM ($services)"); // selects services table $servicesFields_num = mysql_num_fields($servicesResult); // grabs number of fields from services table } function supportMenu($support, $supportResult) { $supportResult = mysql_query("SELECT * FROM ($support)"); // selects support table $supportFields_num = mysql_num_fields($supportResult); // grabs number of fields from support table } ?> This is a file called "menu.php" and I will be including it in another file called "index.php". If needed, I can post the content of "index.php" Link to comment https://forums.phpfreaks.com/topic/206205-im-having-some-serious-issues/ Share on other sites More sharing options...
Mchl Posted June 29, 2010 Share Posted June 29, 2010 Why are you putting table name in ()? Do you plan to have more than one 'about' table? If not, why parametrise it? If yes... no you don't. Link to comment https://forums.phpfreaks.com/topic/206205-im-having-some-serious-issues/#findComment-1078813 Share on other sites More sharing options...
KevinM1 Posted June 29, 2010 Share Posted June 29, 2010 Also, you seem to have some confusion regarding what a function's argument list actually is. The variables listed in an argument list are passed into the function. Your various result variables (e.g., $aboutResult) don't exist outside of the function, but are rather created within the function. Since they're not being passed into the function, they shouldn't be listed as an argument (and you'll probably get an error about passing an undefined variable into the function if you don't fix it). You should have functions that look like: function aboutMenu($about) { $aboutResults = mysql_query("SELECT * FROM $about"); $numAbout = mysql_num_fields($aboutResults); // continue processing, or return a value } Link to comment https://forums.phpfreaks.com/topic/206205-im-having-some-serious-issues/#findComment-1078819 Share on other sites More sharing options...
Dakafall Posted June 29, 2010 Author Share Posted June 29, 2010 Oh! So I had kind of the right idea. If I wanted to return something, I would have it be like this : function aboutMenu($about) { $aboutResult = mysql_query("SELECT * FROM $about"); $aboutFields_num = mysql_num_fields($aboutResult); return $aboutFields_num; } Link to comment https://forums.phpfreaks.com/topic/206205-im-having-some-serious-issues/#findComment-1078832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.