• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp
KEEP IN TOUCH

Posts tagged limit

Web Dev > Populate PHP/HTML table from MySQL database

Jan11
2012
13 Comments Written by Scott Rowley

Hey again all, for this post I’ll be covering how to populate a PHP/HTML table by way of looping through a table in mysql. I’ll be using the sample database provided by http://www.mysqltutorial.org/mysql-sample-database.aspx which has to do with models (cars, planes, ships, etc). Everyone has differing levels of knowledge so I’ll be including some basics as well such as connecting to the mysql database (and closing it later on).

The table we’ll be using in the database is ‘products’. It has the following columns:

productCode        - A unique inventory number
productName        - Name of the product
productLine        - Basic descriptor, 'Motorcycles', 'Classic Cars', etc
productScale       - This models scale size
productVendor      - Company that built the model
productDescription - Detailed description of product
quantityInStock    - Current number of quantity in stock
buyPrice           - Listed price on the "website"
MSRP               - Manufacturers Suggested Retail Price

If I know I’m going to be using my mysql database in multiple files I’ll always throw the connection in something like a ‘dbconnect.php’ file. Here’s an example:

<?php
  mysql_connect(DBHOST, DBUSER, DBPASS) or die(mysql_error());
  mysql_select_db(DBNAME) or die(mysql_error());
?>

Now you can include this in every file, or better yet in your header file which will get included everywhere else. So for example in your header.php file you could throw in:

<?php
  require_once('dbconnect.php');
?>

Alright, so now you’ve got your connection to your database and the appropriate database selected. We’ll skip over the other content that you want to eventually add and say (for this example) that we want to list all of our models. We’ll look at doing this a few different ways, first off we’ll go simple and just request everything from the database and then we’ll tell php how to spit that all out to us.
READ MORE »

Posted in MySQL, PHP, Web Development - Tagged connect, html, loop, MySQL, nest, nested, php, query, result, select, sql, where, while
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Sudo Bash Member sites

Iowa SAR
Des Moines, Iowa Tattoo & Piercing
The Man In Black

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

RSS HowToGeek

  • Facebook Is Using Dark Patterns To Undermine EU Privacy Rules
  • ‘My Time at Reddit Made the World a Worse Place’ Says Former Head of Product
  • What’s the Difference Between Bitcoin, Bitcoin Cash, Bitcoin Gold, and Others?
  • Geek Trivia: When Khrushchev Visited IBM’s California Facility In 1959, He Brought The Concept For What Home With Him?
  • Six Of The Best In-Ear Noise Canceling Earbuds

RSS TheGeekStuff

  • Happy New Year 2018 – From Geek, Dolls and Penguins
  • How to Install Configure LDAP Client for 389 Directory Server
  • 15 mysqlbinlog Command Examples for MySQL Binary Log Files
  • How to View Chrome OS Current version and Force Update Chromebook OS
  • 7 Nginx Rewrite Rule Examples with Reg-Ex and Flags

RSS LifeHacker

EvoLve theme by Blogatize  •  Powered by WordPress Sudo Bash
By Geeks - For Geeks

Back to Top