Getting list values dyanmically from website

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geetamadhavi
    New Member
    • Nov 2008
    • 2

    Getting list values dyanmically from website

    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    • didoamylee
      New Member
      • Nov 2008
      • 16

      #3
      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_hos t"; // most of the times is "localhost"
      $dbuser = "your_mysql_use r";
      $dbpassword = "your_mysql_pas sword";
      $dbname = "your_mysql_dat abase_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("SE LECT * FROM yor_database_ta ble");
      while($row = mysql_fetch_arr ay($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.

      Comment

      Working...