Jump to content
php.lv forumi

Ka to uzrakstii?


ermucis

Recommended Posts

ja tu domaa html tabulaa izvadiit sql tabulu, tad tas jaadara apmeeram shaadi

 

select * from tabula;

 

while($masiivs = mysql_fetch_array($sql_rezultaats)) {

print_r($masiivs );

}

 

par noformeejumu padomaa pats

Link to comment
Share on other sites

Pievienoshu labu un vienkaarsu tabulas izvadi tabulaa! Tas visiem, kas saak ar PHP .. ;)

 

<?php
$db = mysql_connect("localhost", "", "");
mysql_select_db("support",$db);
$result = mysql_query("SELECT * FROM products",$db);
echo "<table border=1>\n";
echo "<tr><td>Class</td><td>Product number</td><td>Hardware</td><td>Warranty</td><td>Warranty tipe</td><td>Service level</td><td>Year</td><td>Priece</TD></tr>\n";
while ($myrow = mysql_fetch_row($result)) {
 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
 $myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6], $myrow[7]);
}
echo "</table>\n";
?>

Link to comment
Share on other sites

Es gan kaut kā universālāk (jebkuram pieprasījumam):

<?php

...

$result = mysql_query("SELECT * FROM products");

echo '<table><tr>';

$fields=@mysql_num_fields($result);

$column=-1;

//izvadām kolonnu nosaukumus kā header rūtiņas

while(++$column<$fields)

echo '<th>'.@mysql_field_name($result,$column).'</th>';

@mysql_data_seek($result,0);

echo "</tr>\n";

//ar vienu rāvienu izvadām atgriestos datus

while($data=mysql_fetch_assoc($result))

echo '<tr><td>'.join('</td><td>',$data)."</td></tr>\n";

echo '</table>';

flush();//šis lai ātrāk tabula izvadās

?>

Link to comment
Share on other sites

×
×
  • Create New...