Here is code to fetch the data from database and display it with loop
#!/usr/bin/perl
use Mysql;
print "Content-type: text/html \n\n";
# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "store";
$tablename = "inventory";
$user = "username";
$pw = "password";
# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);
# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM $tablename";
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);
# HTML TABLE
print "
id |
product |
quantity |
";
# FETCHROW ARRAY
while (@results = $execute->fetchrow()) {
print "" .$results[0]." | " .$results[1]." | " .$results[2]." |
";
}
print "
";
No comments:
Post a Comment