473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to display MySQL tables

Hi
I am a novice in MySQL/PHP/Apache.... I have just created a database in MySQL and would like to see my tables diplayed in a website.

Does anyone know the code for creating forms for this?

I will really be gratefull for any help. Thanks in advance
Feb 19 '07 #1
8 3067
ronverdonk
4,258 Expert 4TB
Have a look at THIS tutorial on PHP and THIS one on displaying MySQL data.

Ronald :cool:
Feb 19 '07 #2
Hi Ronald/Ronverdonk

Thanks for the sites I have had a look at them and now I have a clue of how to start. I will read the notes in detail and have a go at creating my first Dbase.

Have a good day
Preston
Feb 20 '07 #3
ronverdonk
4,258 Expert 4TB
Glad I could help you out to get started.

Ronald :cool:
Feb 20 '07 #4
Hi,
I am really grateful to the help that I have received from theScripts developer network community members especially Ronald. It is unbelievable how I am getting to grips with PHP and MySQL. I have managed to create a database and display it as a Form.

At the moment I am having a slight problem….. Below is my code

while ($row = mysql_fetch_array($result)) {
echo "Student No:".$row{'studentNo'}." Name:".$row{‘Name’}."Age: ".
$row{‘age’}."<br>";

When I try to display the information the column headings are displayed on every row, Like the one displayed below:

Student No:0023 Name:Paul Age:26
Student No:0034 Name:Camilla Age:23
Student No:0044 Name:Peter Age:20
Student No:0055 Name:Kirsty Age:21
Student No:0056 Name:Paul Age:23

I would like to have it display information as shown below:
Student No Name Age
0023
0034

Is there a code that I have typed wrongly or I need to do something more? What about if I want to enter the data through the forms do I have to write a code for this?

Any help/pointing in the right direction will be greatly appreciated. Thanks
Regards,
Oburalia
Feb 23 '07 #5
ronverdonk
4,258 Expert 4TB
In order to get the results vertically aligned properly, you can use a table for your display. To caccomplish what you want: there are 2 ways of doing this:
(1) echo the fixed headers and fixed column values
(2) echo the content of your result dynamically, so when you change the no of columns in your select you don't have to change your echo statement.
The following code is for option 2 results:

[php]
// perform select query
$result=mysql_query("SELECT * from tablea")
or die ("invalid query: ".mysql_error());

// display only when there are results
if (mysql_num_rows($result) > 0) {

// get the number of columns inn the result
$numfields = mysql_num_fields($result);

// start the output table
echo "<table><tr>";

// loop and echo all column names
for ($i=0; $i < $numfields; $i++) { // header
echo '<th>'.mysql_field_name($result, $i).'</th>';
}
echo "</tr>";

// loop and display all column values
while ($row = mysql_fetch_row($result)) { // Data
echo '<tr><td>'.implode($row,'</td><td>')."</td></tr>";
}

// close the output table
echo "</table>";
}[/php]

Ronald :cool:
Feb 23 '07 #6
Hi Ronald
Thanks a lot for your help………. below is the code for my student table, I have a problem, all the rows and columns are now displayed in one long line.
I have tried to check where I could be going wrong in vain….. could you please check that I haven’t left anything out? Sorry for being a pain today.
Regards,
Oburalia

// performing select query
$result=mysql_query ("SELECT * FROM student")
or die ("invalid query:".mysql_error());

//displaying only when there are results
if (mysql_num_rows($result) > 0) {

// getting the number of columns in the result
$numfields = mysql_num_fields($result);

//starting the output table
echo "<student><tr>";

//loop and echo all column names
for ($i=0; $i <$numfields; $i++) { //header
echo'th' .mysql_field_name($result, $i). '</th>';
}
echo "</tr>";
//lopp and display all column values
while ($row = mysql_fetch_row($result)) { // data
echo '<tr><td>'.implode($row,'</td><td>')."</td></tr>";

//closing the output table
echo "</student>";
}
}

?>
Feb 23 '07 #7
ronverdonk
4,258 Expert 4TB
Read the Posting Guidelines in this forum before you show any code!!
Especially the part about enclosing shown code within php or code tags!!


Why did you change the <table> tags into <student> tags? Why? That is not an HTML tag. You also changed a <tr> tag into a tr string. Again: why?

It worked as shown and I don't want to go through each statement you changed. So use the code I showed and it works.

Ronald :cool:
Feb 23 '07 #8
I found your example helpful. I do have a problem with the column names not lining up properly. Is there an additional tag to add to the <th> tag to current things or is it done in the data area?

LastName FirstName Village PhoneNumber Fax
Abad Dennis Leone 688-1318
A'asa Mataua Futiga 699-7895



Read the Posting Guidelines in this forum before you show any code!!
Especially the part about enclosing shown code within php or code tags!!


Why did you change the <table> tags into <student> tags? Why? That is not an HTML tag. You also changed a <tr> tag into a tr string. Again: why?

It worked as shown and I don't want to go through each statement you changed. So use the code I showed and it works.

Ronald :cool:
Apr 26 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mark Adams | last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail server running for several months. It took me a week or so to get it up and running in September. Now, I did a clean upgrade to...
0
by: Mark Adams | last post by:
I really need some help with this. MySQL will not start on boot despite everything I've done to make sure that it is set to do so. When I start it as root from a terminal with...
0
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
1
by: Prof. Goofy | last post by:
hi all, i need to display all my tables from the mySQL database in a table on an ASP/Javascript page, each as a link, so that when clicked, it wil open the selected table for editing. unable to do...
4
by: Vanessa | last post by:
Hi there I am an Access developer, and I have written applications for a 30 telephone call center, using the standard multiuser jet engine, it all works fine, but I want to move our systems onto...
24
by: Phil Latio | last post by:
Let's say I have a simple web application running with just two MySQL tables. The tables structure is as follows: Table: category category_id (PK) category_name parent_category (FK)...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.