Answer the question
In order to leave comments, you need to log in
How to output a specific row from a MySQL database?
Good day !
I recently started learning MySQL and PHP, so I'm still stupid in these languages.
Let's say there is a database with a table and the following lines: id, author, text_name
For example:
id | auther | text_name |
one | pupkin | news 1 |
2 | Fedorov | news 2 |
3 | Sidorov | news 3 |
4 | Ivanov | news 4 |
$db = mysql_connect ("сервер","название","пароль");
mysql_select_db ("название",$db);
mysql_set_charset (utf8);
$result = mysql_query ("SELECT author FROM full_text",$db);
$myrow = mysql_fetch_array ($result);
<? echo $myrow ['author']; ?>
Answer the question
In order to leave comments, you need to log in
Use mysqli , not mysql!
$db = new mysqli("сервер","название","пароль", "БД");
$result = $db->query ("SELECT author FROM full_text", MYSQLI_USE_RESULT);
while($row = $db->fetch_row()){
//Что-то делаем с $row - каждой строкой из таблицы
}
Wow, read further tutorials, you have a complete misunderstanding of the principles of obtaining data.
In order to get all the data, you need to run mysql_fetch_array in a loop:
while(($row=mysql_fetch_array($result))!==false)
{
echo $row['author'];
}
$data_arr=array();
while(($row=mysql_fetch_array($result))!==false)
{
$data_arr[]=$row['author'];
}
This
$result = mysql_query ("SELECT author FROM full_text",$db);
$result = mysql_query ("SELECT author FROM full_text",$db);
$authors = array();
while ($row = mysql_fetch_array ($result))
{
$authors[] = $row['author']
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question