Solved

Get data from MySQL to fill in data in a webpage

Posted on 2004-11-02
291 Views
Last Modified: 2011-08-18
Hello. I am going to create a webpage that gets data from a MySQL table on a Linux server to populate a table in a webpage.

How would I go about doing that?

0
Question by:DBDevOne
    7 Comments
     
    LVL 1

    Expert Comment

    by:Codeit1978
    First What scripting language is your page in?
    0
     

    Author Comment

    by:DBDevOne
    The language doesn't matter. I'm open for suggestions.
    0
     
    LVL 16

    Expert Comment

    by:alain34
    php is the most widely used scripting language on the linux platform for creating dynamic webpage. It is really straightforward as well. It is also platform independant, therefore you can even make it work on windows.
    Check out http://www.php.net
    0
     
    LVL 3

    Accepted Solution

    by:
    HELLO.

    I HAVE TRIED WITH PHP. AND THE SCRIPT FOR THE SAME IS GIVEN BELOW ...

    <?
    //making connection to the database
    $host = "192.1.1.204";//give ip of your mysql server
    $user = "root"; // give user name to login mysql database
    $pwd = ""; // give password of your mysql database
    $db = "mydb"; // give database name

    $link = mysql_connect($host , $user , $pwd) or die ("Couldn't connect to server.");
    $db = mysql_select_db($db) or die ("Couldn't select the database.");

    //HERE WE HAVE MADE THE CONNECTION TO THE DATABASE

    //NOW MAKING QUERY FOR GETTING RECORDS from table1

    $strQuery = "select * from table1";

    $resultSet = mysql_query($strQuery) or die("Error occured while getting detail from table1.");

    //now checking if retrieved records are more than zero
    if(mysql_num_rows($resultSet)>0)
    {
      //fetching result in the variable
      while($rowResult = mysql_fetch_array($resultSet))
      {
        //printing detail on the browser
        echo $rowResult[0]."<br>";
      }
    }

    //free sql retrieved result
    mysql_free_result($resultSet);
    ?>

    This script works fine.

    Rest if you didnt get it then feel free to ask me further. I would glad to cooperate you.

    With regards,
    Jankit
    0
     
    LVL 3

    Expert Comment

    by:Jankit141180
    Hello

    One more thing in concern with my previous post  ....

    I have not included any HTML formatiing in my script.
    The script will print only first column on the browserand accordingly you are requested to do formatting.

    Thank You
    -Jankit
    0
     

    Expert Comment

    by:Ultimat
    This example is a php example ( with mysql ).
    This is a bit shorter and perfect for writing your first databasedriven script ( in the future it is beter to exclude the first part and put in an other file , so it is better to make updates f.e. username , otherwis you have to change it on each page - for this use include)

    $hostname_db = "server";
    $database_db = "databasename";
    $username_db = "username";
    $password_db = "pwd1";
    $db = mysql_pconnect($hostname_db, $username_db, $password_db) or trigger_error(mysql_error(),E_USER_ERROR);

    mysql_select_db($database_db, $db);
    $query_producten = "SELECT * FROM producten ";
    $producten = mysql_query($query_producten, $db) or die(mysql_error());
    $row_producten = mysql_fetch_assoc($producten);

    do{
       echo($row_producten['field']);
    } while ($row_producten = mysql_fetch_assoc($producten));

    Greetz Ultimat
    0
     

    Author Comment

    by:DBDevOne
    Thank you very much Jankit and thank you all for the comments. I appreciate it!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    The first time you look at a web page and its source code, you are probably a little intimidated by the use of symbols and jargon that really looks foreign to you. You might not even know where to start to begin learning what it all means. That’…
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now