Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:33:06+00:00 2026-06-15T05:33:06+00:00

I need help displaying data from mysql to a webpage, I am coding in

  • 0

I need help displaying data from mysql to a webpage, I am coding in php.

My database consists of products which are cars(same type e.g Chevy), right now I have 2 rows (I can add more if I want to), each cars contains the image path, and description.

I can show one row (car) but I am unable to show all rows. I know I have to go through a loop to get all the data from the cars database but I am not sure how to implement it.

This is what I have so far. Assuming I already connected to my database
note: the image path I would like to show the picture in my website.

This is how i would like it to display in my webpage:

    $query = "SELECT * FROM cars where cars.carType = 'Chevy' AND \
    cars.active = 1";
    $numberOfFieds = mysqli_num_fields($result);
    $numberOfRows = mysqli_num_rows($result);

   /* Gets the contents */
   $row = mysqli_fetch_row($result);
   $rows = mysqli_fetch_assoc($result);
   $fieldcarssontable = array_keys($row);



  echo "<table>";

  while($row = mysqli_fetch_assoc($result)){
   echo "<th>" . $fieldcarssontable[imgPath] . "</th>";
   echo "<th>" . $fieldcarssontable[description] . "</th>";

  }


  echo "</tr>";

  echo "</table>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:33:07+00:00Added an answer on June 15, 2026 at 5:33 am

    Just add a while loop. mysqli_fetch_assoc returns a row and moves the internal pointer to the next row until all rows are fetched, then it returns false and the while loop will stop

    Pseudo syntax to understand while

    while ( this is true ) {
         execute this
    }
    

    So on your case you can say

    while ( $row = mysqli_fetch_assoc( $result ) ) {
       // process/output $row
    } 
    

    mysqli_fetch_assoc and mysqli_fetch_row literally do the same, assoc gives you the array with your result field names as index so this is simpler to access ( $row[‘name’] rather than $row[0] when using fetch_row )

    Have fun! 🙂

    EDIT

    // connect to your database server
    $link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
    
    // an error occured
    if (!$link) {
        die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
    }
    
    // build your query
    $query = "SELECT 
                   *      # select actual fields instead of *
              FROM 
                   cars
              WHERE
                   cars.carType = 'Chevy'
              AND
                   cars.active = 1";
    
    // execute query
    $result = mysqli_query($link, $query );
    
    if ( !$result ) {
         die( 'no result' );
    }
    
    // number of fields
    $numberOfFields = mysqli_num_fields($result);
    
    // the field names
    $fieldNames     = mysqli_fetch_fields($result);
    
    // number of result rows
    $numberOfRows = mysqli_num_rows($result);
    
    // watch the content of fieldName and compare it with the table header in the output
    print_r( $fieldName );
    
    echo "<table>\n";
    
    // table header, not neccessary to put this into a loop if the query isn't dynamic 
    // so you actually know your field names - you can echo the header without any variable.
    // for the sake of learning about loops I added this
    
    foreach( $fieldNames as $index => $fieldName ) {
        echo "\t<th>field #" $index . ", name:" . $fieldName . "</th>\n";
    }
    
    // now it's time to walk through your result rows, since we only need to check for "true" a while loop does best
    
    while ( $row = mysqli_fetch_assoc( $result ) ) {
        echo "\t<tr><td>" . $row['imgPath'] . "</td><td>" . $row['description'] . "</td></tr>\n";
    }
    
    echo "</table>\n";
    
    // remove the result from memory
    mysqli_free_result( $result );
    
    mysqli_close( $link );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused about displaying data from a MySQL database. I would like
I need help in displaying an image from database. I've read that it's efficient
Hello I need help with displaying data from 2 table. So i Have 2
Need help writing a script downloads data from google insight using c# this is
I need help in displaying my images from the directory images on my public_html
My application is fetching a data dynamically from MYSQL and displaying. The Problem is
I'm trying to display set of data which have retrieved from the sql database
I'm running MySQL 5.0.88 and need to select data from two tables, called articles
I need help rendering data in PHP: I want to use the results of
I am designing a job rota planner for a company and need help displaying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.