By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Getting list values dyanmically from website

P: 2
Hi All,

I am a java developer got a php project from the office how to create a list.values in the list should come from the database MYSQL what to do for this please help me out as early as possible.

Thanks in Advance,

Geeta
Nov 7 '08 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
Hi.

You would obviously have to have PHP fetch the data from your MySQL database and print it into this list you need. You could use the Improved MySQL extension to get the data, and the echo statement to print it.

Give it a try and let us know if you run into any problems.
Nov 8 '08 #2

didoamylee
P: 16
Hy,

You must first connect to the database. There are many ways to connect to the database. I will present one simple example. First create a config.php file an write:
[PHP]<?php
$dbhost = "your_mysql_host"; // most of the times is "localhost"
$dbuser = "your_mysql_user";
$dbpassword = "your_mysql_password";
$dbname = "your_mysql_database_name";

$conn = mysql_connect($dbhost,$dbuser,$dbpassword) or die("Can not connect to MySQL!");
mysql_select_db($dbname, $conn) or die("Can not find the database");

?>[/PHP]

Then in your let's say list.php write:

[PHP]<?php
require("config.php");

$q = mysql_query("SELECT * FROM yor_database_table");
while($row = mysql_fetch_array($q)) {
echo $row['your_database_table_column'];
}
?>[/PHP]

There are many ways you can do that. I wanted to present one simple approach.
I must admit i did not verified the code. I've just wrote it as I knew at the moment.

Hope it helps.
Nov 8 '08 #3

Post your reply

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