Results 1 to 10 of 12

Thread: Day 13 - MySQL - Become PHP Expert in 30 days

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by stefin View Post
    I corrected the code. Thank you for the help.

    http://php.flashwebhost.com/stefin/mysql_1.php


    Code:
    <?php 
    
    
    $db_server = '127.0.0.1'; 
    $db_user = 'fwhphp_user'; 
    $db_password = 'k5BJRaX6SFbs'; 
    $db_name = 'fwhphp_db'; 
    
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name); 
    
    
    if ($mysqli->connect_errno) { 
        echo 'Connect failed: ' . $mysqli->connect_error; 
        exit(); 
    } 
    
    
    $sql = 'SELECT * FROM `chat`'; 
    $result = $mysqli->query($sql); 
    
    
    echo '<p>MySQL have returned ' . $result->num_rows . ' records.</p>'; 
    
    
    echo '<br>'; 
    echo '<hr>'; 
    
    
    while ($chat = $result->fetch_object()) {
        echo '<b>' .  $chat->name . '</b> says : ' . $chat->message;
        echo '<br>';
        echo '<hr>';
    }

    Very nice, you don't need to remember the code, just use this code with little modification when you need to read data from MySQL.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  2. #2
    Join Date
    Apr 2005
    Posts
    46,704

    Default

    http://php.flashwebhost.com/mini/mysql.php

    Code:
    <?php
    
    $db_server = '127.0.0.1';
    $db_user = 'fwhphp_user';
    $db_password = 'k5BJRaX6SFbs';
    $db_name = 'fwhphp_db';
    
    $mysqli = new mysqli($db_server, $db_user, $db_password, $db_name);
    
    if ($mysqli->connect_errno) {
        echo 'Connect failed: ' . $mysqli->connect_error;
        exit();
    }
    
    $sql = 'SELECT * FROM `chat`';
    $result = $mysqli->query($sql);
    
    echo '<p>MySQL have returned ' . $result->num_rows . ' records.</p>';
    
    echo '<br>';
    echo '<hr>';
    
    while ($chat = $result->fetch_object()) {
        echo '<b>' .  $chat->name . '</b> says : ' . $chat->message;
        echo '<br>';
        echo '<hr>';
    }

  3. #3
    Join Date
    Feb 2007
    Posts
    26,214

    Default

    DAY 13 PHP PROGRAMMING

    http://php.flashwebhost.com/tom/day_13_mysql_read.php

    PHP Code:

    <?php
    $db_server 
    '127.0.0.1';$db_user 'fwhphp_user';$db_password 'k5BJRaX6SFbs';$db_name 'fwhphp_db';
    $mysqli = new mysqli($db_server$db_user$db_password$db_name);
    if (
    $mysqli->connect_errno) {
    echo 
    'connect failed: ' $mysqli->connect_error;exit();}
    $sql 'SELECT * FROM `chat`';$result $mysqli->query($sql);echo '<p>MySql have returned ' $result->num_rows ' records</p>';
    echo 
    '<br>';echo '<hr>';
    while (
    $chat $result->fetch_object()) {
    echo 
    '<b><i>'$chat->name '</i></b> says: ' $chat->message ;
    echo 
    '</br>';echo '</hr>';
    }

  4. #4
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Good, working perfectly. If you don't understand any part, ask here. Some times it take some time to understand stuff properly, so you can skip forward, you can come back later as required. When we have done more code like this, you will get a much better idea and things may get easier.
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

Bookmarks

Posting Permissions

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