M
M
Meyvorrrata2015-05-03 15:14:13
Database
Meyvorrrata, 2015-05-03 15:14:13

How to output values ​​from the database to the finished form?

There was a problem of outputting data to the form (first name, last name, avatar, etc.), how to query the database so that the values ​​appear in their places?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-05-03
@Rsa97

Judging by the question - something like this:
- Would the esteemed Database be kind enough to write down the required data in the fields of this insignificant form.
Since the database type and programming language are not specified, more can hardly be said.

M
Mini MVC, 2015-10-19
@alleroy

What could be the problem? writes:
Fatal error: Call to a member function fetch() on boolean in /customers/b/c/d/bashlam.com/httpd.www/models/News.php on line 38

public static function getNewsList()
    {
        // Запрос к БД

        $host = 'xxxxxx';
        $dbname = 'xxxxxx';
        $user = 'xxxxx';
        $password = 'xxxxxx';
        $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
        
        $newsList = array();
        
        $result = $db->query('SELECT id, title, date, short_content '
                
                . 'FROM news'
                . 'ORDER BY date DESC '
                . 'LIMIT 10');
   
        $i = 0;
        while($row = $result->fetch()){
            $newsList[$i]['id'] = $row['id'];
            $newsList[$i]['title'] = $row['title'];
            $newsList[$i]['date'] = $row['date'];
            $newsList[$i]['short_content'] = $row['short_content'];
            $i++;
        }
        
        return $newsList;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question