2013-03-27 2 views
-1

У меня есть этот код, чтобы выбрать и выходные данные из базы данныхВставка данных в таблице

<?php 

require('system/connect.php'); //load the connection file 

$sql = ("SELECT * FROM `movie`"); // add mysql code to a variable. In this case it will select ALL columns from the database. 

$query = mysql_query($sql); //run the query contained within the variable. 

while ($row = mysql_fetch_array($query)) { //store each single row from the database in an array named $row. While there are any rows left, loop through and execute the following code: 

$id = $row['movie_id']; //gets name from DB for a single row 
$name = $row['movie_name']; //gets age from DB for a single row 
$category = $row['movie_category']; //gets age from DB for a single row 

//Following code outputs the data to the webpage: 

echo $id; 

echo $name; 

echo $category; 
}; 
?> 

страница шоу: 1titanicromance2zoroaction3blood diamondsaction

Мне нужен способ, чтобы сделать таблицу или массив и вставить данные прямо к нему.

+0

Ну, вы наверняка можете начать с вывода HTML. –

+0

Это базовый PHP. Либо помещаем его в массив, либо выплевываем HTML. С какой частью вам нужна помощь? Вы уже пробовали? –

+0

Downvoters, если вам не нравится, что n00bs задают здесь вопросы, то не читайте их вопросы. В какой-то момент мы все были n00bs, и все задавали глупые вопросы. Это правильный вопрос. – dbDev

ответ

1

Добавление в HTML для таблицы должно делать трюк. Хотя, это дрянное кодирование для смешивания PHP и HTML.

<?php 

require('system/connect.php'); //load the connection file 

$sql = ("SELECT * FROM `movie`"); // add mysql code to a variable. In this case it will select ALL columns from the database. 

$query = mysql_query($sql); //run the query contained within the variable. 

echo '<table>'; 

while ($row = mysql_fetch_array($query)) { //store each single row from the database in an array named $row. While there are any rows left, loop through and execute the following code: 

$id = $row['movie_id']; //gets name from DB for a single row 
$name = $row['movie_name']; //gets age from DB for a single row 
$category = $row['movie_category']; //gets age from DB for a single row 

//Following code outputs the data to the webpage: 
echo '<tr>'; 

echo '<td>' . $id . '</td>'; 

echo '<td>' . $name . '</td>'; 

echo '<td>' . $category . '</td>'; 

echo '</tr>'; 

}; 

echo '</table>'; 

?> 
+0

Я хотел проголосовать +1 ... но у меня все еще нет 1 репутации ... anw thnks для помощи ур: D – ouzoumzak

+0

@ouzoumzak Если вы считаете, что это правильный ответ, вы можете нажать на зеленый флажок рядом с ним. – dbDev

+0

сделано .. спасибо – ouzoumzak

0

Вы имели в виду HTML-стол? Тогда это будет выглядит так

<?php 

require('system/connect.php'); //load the connection file 

$sql = ("SELECT * FROM `movie`"); // add mysql code to a variable. In this case it will select ALL columns from the database. 

$query = mysql_query($sql); //run the query contained within the variable. 

if (mysql_num_rows($query)) { // if there is some rows in result 
    echo "<table>"; // starting HTML table 
    while ($row = mysql_fetch_array($query)) { //loop through the result       
     echo "<tr>". 
       "<td>".$row['movie_id']."</td>". 
       "<td>".$row['movie_name']."</td>". 
       "<td>".$row['movie_category']."</td>". 
      "</tr>"; 
    } 
    echo "</table>";// finishing HTML table 
} 
?> 

ПРИМЕЧАНИЕ: не использовать mysql_* функции. Они устарели. Используйте вместо этого PDO или Mysqli.

Смежные вопросы