Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.