www.webdeveloper.com
Results 1 to 4 of 4

Thread: display mysql database in HTML div element

  1. #1
    Join Date
    Mar 2009
    Posts
    31

    display mysql database in HTML div element

    Hello, I was wondering how I can grab information from the mysql database and place that information into a specified HTML div element.

    Here is my PHP that I am using to connect to the database:
    PHP Code:
    <?php

    $mysql 
    = new mysqli('localhost''root''root''ajax_demo') or die('you\'re dead');
    $result $mysql->query("SELECT * FROM explore") or die($mysql->error);

    if(
    $result) {
        
        while(
    $row $result->fetch_object()) {
            
    $siteName[] = $row->site_name;
            
    $siteDescription[] = $row->site_description;
            
    $siteURL[] = $row->site_url;
            
    $sitePrice[] = $row->site_price;
            
            
    # note that this isn't ideal - to echo out text before the doctype. This is just for example. In a real-world app, we'd echo this info out within the container div.
        
    }
    }
    Any help would be great. Thanks.

  2. #2
    Join Date
    Feb 2009
    Posts
    162
    Yes, you can do this by using Ajax.

    Go to Wschool and find some example.

    Here is the latest phone by Samasung

    samsung i637 Jack

  3. #3
    Join Date
    Mar 2009
    Posts
    31
    I would still like to view the page source and see that the information is there. When I use ajax, nothing appears in the source.

  4. #4
    Join Date
    Mar 2009
    Posts
    31
    Would something like this be the proper way to go? it seems like it will get messy since I need to grab lots of data from the DB.

    PHP Code:
    <div id="container">    
        <ul>
            <?php foreach($siteName as $n) echo "<li> $n </li>\n"?>
        </ul>
    </div>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles