silver_fox Posted February 13, 2015 Share Posted February 13, 2015 Hi, im a following a tutorial in order to create a eCommerce website, I'm at the early stages of the tutorial but I've come across a hurdle where I'm unable to display dynamic data from my website. In myPHPadmin i have created a table with 2 rows (cat_id and cat_title). I've inserted data into these rows as follows; cat_ids cat_title 1 chinese 2 japanese 3 malaysian 4 thai this is the data I'm trying to display on my website. Following the tutorial i created a functions.php file which contains the following code to retrieve the categories data. ----------------------------------- <?php $con = mysqli_connect("localhost", "root", "", "ecommerce"); // getting the categories function getCats () { global $con; $get_cats = "select * from categories"; $run_cats = mysqli_query($con, $get_cats); while ($row_cats = mysql_fetch_array($run)) { $cat_id = $row_cats ['cat_ids']; $cat_title = $row_cats['cat_title']; echo "<li><a href = '#'>$cat_title</a>li"; } } ?> --------------------------------------- The next step was displaying this data to my index.php page which i did using the following code <div id="sidebar" > <div id = "sidebar_title"> Menus </div> <ul id= "cats"> <?php getCats (); ?> <ul> ---------------------- This should display the four categories i created according to the tutorial but it does not display on my index page, i receive no errors either. I've revised the code multiple times but can't see any errors or anything different I've done. Any help will be much appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/ Share on other sites More sharing options...
requinix Posted February 14, 2015 Share Posted February 14, 2015 You're mixing mysql and mysqli commands in there and passing the wrong variable (to the wrong function). Quote Link to comment https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/#findComment-1505652 Share on other sites More sharing options...
silver_fox Posted February 14, 2015 Author Share Posted February 14, 2015 You're mixing mysql and mysqli commands in there and passing the wrong variable (to the wrong function). Hi Ive changed the code so they all reflect mysqli now. can you expand on this please 'passing the wrong variable (to the wrong function).' I'm new to PHP so I'm a little confused. Quote Link to comment https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/#findComment-1505653 Share on other sites More sharing options...
requinix Posted February 14, 2015 Share Posted February 14, 2015 $run_cats = mysqli_query($con, $get_cats); while ($row_cats = mysql_fetch_array($run)) {You call it "run_cats" on the first line but "run" on the second. Quote Link to comment https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/#findComment-1505656 Share on other sites More sharing options...
silver_fox Posted February 14, 2015 Author Share Posted February 14, 2015 $run_cats = mysqli_query($con, $get_cats); while ($row_cats = mysql_fetch_array($run)) {You call it "run_cats" on the first line but "run" on the second. Thank you! such a stupid mistake. Appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/#findComment-1505683 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.