Jump to content
php.lv forumi

datu izvadiishana


jonass

Recommended Posts

taa - man ir mysql datubaase ar tabulu. tabulaa ir 5 lauki, no kuriem viens ir id, bet paareejie tiek ierakstiiti no postformas(lietotaaja ievadiiti). ar katru jaunu ierakstu id palielinaas par vienu. es varu dabuut aaraa datus tikai tur, kut ir kaada noteikta id veertiiba piem. 4, bet kaa lai dabuu visus laukus aaraa(tiem dazhaads id) ? shai izvadiishanai janotiek arii pie jauna rowa izveidoshanas.

kods ir shaads :

<?
$hostname = "myhost"; 
$dbuser = "myuser"; 
$dbpass = "mypass"; 
$dbname = "mydbase"; 
$usertable = "mytable"; 
mysql_connect($hostname,$dbuser,$dbpass) 
mysql_select_db("$dbname") 
mysql_query("INSERT INTO $usertable (lauks1,lauks2,lauks3,lauks4) VALUES ( '$_POST[f1]','$_POST[f2]','$_POST[f3]','$_POST[f4]')");
$visi = mysql_query("SELECT * FROM $usertable"); 
$row = mysql_fetch_array($visi);
$r1 = $row['lauks1'];
$r2 = $row['lauks2'];
$r3 = $row['lauks3'];
$r4 = $row['lauks4'];
echo '<table align="center" width="50%"><tr><td align="center">';
echo '1. lauks : ' . $r1 . '<br />';
echo '2. lauks : ' . $r2 . '<br />';
echo '3. lauks : ' . $r3 . '<br />';
echo '4. lauks : ' . $r4 . '<br /><hr width="50%" />';
echo '</td></tr></table>';
?>

Link to comment
Share on other sites

megjini sjita..

 

<?
$hostname = "myhost"; 
$dbuser = "myuser"; 
$dbpass = "mypass"; 
$dbname = "mydbase"; 
$usertable = "mytable"; 
mysql_connect($hostname,$dbuser,$dbpass) 
mysql_select_db("$dbname") 
mysql_query("INSERT INTO $usertable (lauks1,lauks2,lauks3,lauks4) VALUES ( '$_POST[f1]','$_POST[f2]','$_POST[f3]','$_POST[f4]')");
$visi = mysql_query("SELECT * FROM $usertable"); 

echo '<table align="center" width="50%">';

while ($row = mysql_fetch_array($visi)) {

 $r1 = $row['lauks1'];
 $r2 = $row['lauks2'];
 $r3 = $row['lauks3'];
 $r4 = $row['lauks4'];

 echo '<tr><td align="center">';
 echo '1. lauks : ' . $r1 . '<br />';
 echo '2. lauks : ' . $r2 . '<br />';
 echo '3. lauks : ' . $r3 . '<br />';
 echo '4. lauks : ' . $r4 . '<br /><hr width="50%" />';
 echo '</td></tr>';
}

echo '</table>';
?>

Link to comment
Share on other sites

×
×
  • Create New...