Jump to content

Dynamic Data from the Database


silver_fox

Recommended Posts

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.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/294591-dynamic-data-from-the-database/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.