Page 1 of 1

Data Retrieval and Table Display

Posted: Sun Oct 30, 2011 10:37 am
by DarkSinister
Okay so I need to make a database and then I have to display it using my xampp server kinda thing. Ummm... This database is more like an inventory that I need to display on the browser in a table format.

This is the following code that I made and imported using PHPmyAdmin...
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 29, 2011 at 09:25 AM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `school_of_engineering`
--

-- --------------------------------------------------------

--
-- Table structure for table `Inventory`
--

CREATE TABLE IF NOT EXISTS `inventory` (
`ID` varchar(10) NOT NULL,
`Name` varchar(20) NOT NULL,
`Qty` int(10) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `Inventory`
--

INSERT INTO `Inventory` (`ID`, `Name`, `Qty`) VALUES
('1', 'Breadboard', 1),
('10', 'Utility Cutter', 2),
('12', 'Screwdriver', 1),
('13', 'Phillip screwdriver', 1),
('15', 'Long nose plier', 1),
('16', 'Combination Plier', 1),
('17', 'Adjustable Spanner', 1),
('18', 'Ring Spanner', 1),
('2', 'Glue Gun', 1),
('21', 'Digital multimeter', 1),
('22', 'Analogue multimeter', 1),
('25', 'Multi Extension', 1),
('26', 'Measuring Tape', 1),
('28', 'Semi-Circle File', 1),
('29', 'Triangle File', 1),
('3', 'Soldering Iron', 1),
('30', 'Square File', 1),
('31', 'Round File', 1),
('32', 'Flat File', 1),
('33', 'Bench Vice', 1),
('34', 'Multi-Adapter', 1),
('35', 'Hacksaw', 1),
('36', 'Hand Saw', 1),
('37', 'Metal Ruler', 1),
('39', 'Goggle', 1),
('4', 'Soldering stand & sp', 1),
('40', 'Battery Drill', 1),
('41', 'Electric Hand Drill', 1),
('42', 'Jig saw', 1),
('43', 'Hammer', 1),
('44', 'Mallet', 1),
('45', 'Drill bits', 1),
('46', 'Mallet', 1),
('5', 'Soldering Lead', 1),
('6', 'De-soldering pump', 1),
('60', 'OSC Probe', 1),
('64', 'BNC - BNC', 1),
('7', 'Wire stripper', 1),
('8', 'Wire cutter', 1);

I'm really confused how to work on the data-retrieval, as well as making it display in a table form.. :banghead:

Please help me..This is my assignment and I've been working on it for a week to get through it... :banghead: :banghead:

Re: Data Retrieval and Table Display

Posted: Sun Oct 30, 2011 10:40 am
by Celauran
Please post the code you've written so far and explain where you're running into problems. We're not going to do your homework for you.

Re: Data Retrieval and Table Display

Posted: Sun Oct 30, 2011 11:20 am
by DarkSinister
Celauran wrote:Please post the code you've written so far and explain where you're running into problems. We're not going to do your homework for you.
Okay so first I tried this code to show the data in a form type, but it still didn't show..
<?php

<form method="get" action="Inventory.sql">
<input type="text" name="Name" value="Name" />
<input type="text" name="Quantity" value="Qty" />
</form>
?>
From what my groupmate of this assignment told me, this code is to retrieve the data from the Inventory.php (the codes which i just showed earlier).
But it doesn't show.. Infact, this is the result it get..
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\check.php on line 3

Re: Data Retrieval and Table Display

Posted: Sun Oct 30, 2011 12:22 pm
by DarkSinister
I tried again with another code to access the database with this code..

*********************************************************************************************

Code: Select all

<?php
session_start();
$db_name ='school_of_engineering';

//create session
//$_session['id']=$_GET['id'];
$_session['id']= 'ID';
//connect to DB
$conn = mysqli_connect ('localhost','root','');
mysqli_select_db($conn,$db_name);


//query the DB
$sql = "select * from user where ID =".$_session['id'];
$query = mysqli_query($conn,$sql);

//display the data
$row = mysqli_fetch_row($query);
echo "<b>ID</b> : $row[1] <br/>";
echo "<b>Name</b> : $row[1] <br/>";
echo "<b>Qty</b> : $row[1] <br/>";
echo "<br>";
echo "<p>";
echo "</p>";
?>
*********************************************************************************************

But it still doesn't work... =(

It shows this instead...
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\check.php on line 18
ID :
Name :
Qty :

Re: Data Retrieval and Table Display

Posted: Sun Oct 30, 2011 9:06 pm
by Celauran

Code: Select all

$_session['id']= 'ID';
//connect to DB
$conn = mysqli_connect ('localhost','root','');
mysqli_select_db($conn,$db_name);


//query the DB
$sql = "select * from user where ID =".$_session['id'];
So far, we've only seen that you have a table called inventory, yet you're trying to query the user table. Is there such a table? If not, that would explain why your query is returning FALSE. Also, you're trying to check for results where the value of column ID is the string "ID", which is almost surely wrong.

For openers, try changing this line:

Code: Select all

$query = mysqli_query($conn,$sql);
To this:

Code: Select all

$query = mysqli_query($conn,$sql) or die(mysqli_error($conn));
This will at least show what error is causing your initial query to fail.