473,386 Members | 1,654 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.

Using PHP to query a MySQL Database table

8
I'm trying to get a php page to show data from a MySQL database. But the problem that I have is I don't know where to start.

I'm very new at PHP and I'm constantly told by others that it's very hard to just jump straight into it, but that's the best way I learn.

All I need to know is how to show all the information I have on a MySQL database table in a table on a web page. From there I should be able to create a form that I can select certain pieces of data to be shown.

If anyone could offer their expertise in this, it would be very appreciative. Thank you.
Sep 26 '06 #1
2 4229
ronverdonk
4,258 Expert 4TB
The following sample reads 3 columns of data (name, address, city) from the MySql database table table_name and displays that on the screen in a HTML table.
[PHP]<?php
$conn = mysql_connect("localhost", "username", "password")
or die($msg_no_connect);
mysql_select_db("vwso")
or die(mysql_error());
$res = mysql_query("SELECT name, address, city FROM table_name;")
or die(mysql_error());
if (mysql_num_rows($res) > 0) {
echo '<table border="1">';
echo '<th>Name</th><th>Address</th><th>City</th>';
while ($row = mysql_fetch_assoc($res)) {
echo "<tr>
<td>{$row['name']}</td>
<td>{$row['address']}</td>
<td>{$row['city']}</td>
</tr>";
}
echo '</table>';
}
else
echo 'No rows in selected table';
?>[/PHP]

Ronald :cool:
Sep 27 '06 #2
samui
8
Awesome thank you so much, that gave me a huge grip on things. Very helpful indeed! =D
Sep 27 '06 #3

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

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
4
by: John Victor | last post by:
In my php page I'm using a mysql database. I want to run a query on a table, then run a second query on the results returned from the first query. In mysql this would be the same as running a...
4
by: 21novembre | last post by:
Hi all, I'm working on my first php+mysql program. I have a mysqld running and there's a DB named "example" with a table "tbl". Here it is: -------------- mysql> use example; Reading table...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
6
by: sheree | last post by:
I would like to create a query where one of the columns of the queries comes from a combo list box on a form. For example, if my table has the following fields: id name interest1 interest2...
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
3
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.