VinceGledhill Posted July 31, 2012 Share Posted July 31, 2012 Hi People. I am running a site which is mainly built around PHP but am using a joomla front end and I'm getting sick of it. This is because every time a new record is added to the DB I have to manually add a link to the menu to make the "airfield card" visible. What I am trying to do is build a DB driven menu. Here is my code for my connection to the DB <?php $host = 'localhost'; $usr = "theusername"; $password = 'thepassword'; $db_name = 'thedbname'; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); ?> Here is my code that is supposed to show me a list of "airfields" from the 'users' DB and dynamically list the 'username' table contents. <?php include("db_connect.php"); $users_sql = "SELECT * FROM users"; $users_query = mysql_fetch_assoc(users_sql) or die (mysql_error()); $rsUsers = mysql_fetch_assoc ($users_query); ?> <h2>News</h2> <div class="scroll"> <h3>31st July 2012</h3> <p class="news">New HTML site created which has made the whole job of adding new airfields that much easier. As soon as you submit an airfield it becomes visible. </div> <li><a href="add.php">Add New Airfield</a></li> <h2>Airfields</h2> <ul> <li><a href="alpha.php">Alpha</a></li> <ul> <?php do { ?> <li><a href=""><?php echo $rsUsers ['username']; ?> </a></li> <?php } while ($rsUsers = mysql_fetch_assoc ($users_query)); ?> </ul> <li><a href="bravo.php">Bravo</a></li> However, all I am getting is a blank area on the site which is in a temporary home here http://www.airfieldcards.com/vg_temp/add.php Please can someone look at my code and tell me where I'm going wrong. Link to comment https://forums.phpfreaks.com/topic/266518-trying-to-build-a-db-driven-menu-for-my-site/ Share on other sites More sharing options...
DavidAM Posted July 31, 2012 Share Posted July 31, 2012 $users_query = mysql_fetch_assoc(users_sql) or die (mysql_error()); $rsUsers = mysql_fetch_assoc ($users_query); That first line should be $users_query = mysql_query(users_sql) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/266518-trying-to-build-a-db-driven-menu-for-my-site/#findComment-1365826 Share on other sites More sharing options...
cpd Posted July 31, 2012 Share Posted July 31, 2012 And your missing the variable identifier ($) - $users_query = mysql_query($users_sql). Link to comment https://forums.phpfreaks.com/topic/266518-trying-to-build-a-db-driven-menu-for-my-site/#findComment-1365828 Share on other sites More sharing options...
VinceGledhill Posted July 31, 2012 Author Share Posted July 31, 2012 Brilliant, thanks guys, that's now working. Link to comment https://forums.phpfreaks.com/topic/266518-trying-to-build-a-db-driven-menu-for-my-site/#findComment-1365838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.