marnix Posted November 30, 2005 Report Share Posted November 30, 2005 man vajag lai visi dati niks emails teksts datums ierakstiitos zem viena ID.... bet man katrs ierakstaas atseviskaa Id... Pasakiet kas par probleemu...luudzu.. <?php $link = mysql_connect('localhost', 'root'); if (!$link) { die('Nevar pievienoties: ' . mysql_error()); } mysql_select_db('datubaze'); mysql_query("INSERT INTO test (niks) values ('marnix')");mysql_query("INSERT INTO test (emails) values ('marnix@inbox.lv')");mysql_query("INSERT INTO test (teksts) values ('es dziivo rīgaa')");mysql_query("INSERT INTO test (datums) values ('11,11,11')"); printf("Pēdējie dati ievadīti zem id %d\n", mysql_insert_id()); ?> Link to comment Share on other sites More sharing options...
Klez Posted November 30, 2005 Report Share Posted November 30, 2005 INSERT INTO test (niks,email,vards,vecums,datums,veel,unveel) VALUES ('marnix','marinix@','peteris','35','2005.11.30','kaut kas','veel kaut kas') Link to comment Share on other sites More sharing options...
ohmygod Posted November 30, 2005 Report Share Posted November 30, 2005 Netaisi entos insertus. Uz katru taksh tev jauns id pieshkjiras (ja ir autoincrement) Raksti visu vienaa!! (mails, teksts) VALUES ('$mails', '$teksts') Link to comment Share on other sites More sharing options...
marnix Posted November 30, 2005 Author Report Share Posted November 30, 2005 ok.. paldiess.. viss straadaa.. thanks Link to comment Share on other sites More sharing options...
Grey_Wolf Posted November 30, 2005 Report Share Posted November 30, 2005 (edited) ("INSERT INTO test (datums) values ('11,11,11')"); spriezot peec shii tu datumu glabaa stringaa... tas nav pats praatiigaakais risinaajums... labaak izmanto DATATIME formaatu... tam ir daudz prieksrociibu viegli vareesi sakaartot datus peec konkreetaa laika/datuma + ierakstot DB vari izmantot SQL f-ju NOW() INSERT INTO test (datums) values ( NOW() ) ierakstiisies tekoshais datums+laiks SQL formataa 2005-11-24 09:52:25 no kura vari dabuut aaraa visu ko velies t. sk. arii paarkartot izvades formaatu sev vajadzigajaa ------ otrs varijants ir glabaat unix time stampu Integer formaataa.. PHP f-ja $time() P.S. katraa zinjaa ne stringaa... edit: izvades formateeshana noSQL SELECT DATE_FORMAT(datums, 'vajadziigais_strings') AS noformets_datums FROM tabula........ izvade buus- 'sodien ir 2005 gada 11 meneseis un 24 menesha diena' piem. vajadziigais_strings='sodien ir %Y gada %c meneseis un %e menesha diena' --------- %Y - aizvietos pret gadu ar 4cipariem 2005 %y - gads ar 2 cipariem 05 ----- laikam kopaa ir 22 sufiksi - galvenais atceries ka vinjisakas ar % un ir liela atskjiriiba starp mazajiem un lielajiem burtiem P.P.S. AS noraada uz psido nosaukumu - pie nolasiishanas $row['noformets_datums'] Edited November 30, 2005 by Grey_Wolf Link to comment Share on other sites More sharing options...
marnix Posted November 30, 2005 Author Report Share Posted November 30, 2005 veel viena probleema .. man tur kur izvada no datu baazes niku mailu textu datumu... vajadzeetu paarveerst mainiigajaas veertiibas piem $niks = $row['niks'] kautkaa taa. bet es nezinu kaa.. paliidziet luudzu... <?php $link = mysql_connect('localhost', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('datubaze'); if (!$db_selected) { die('Could not select database: ' . mysql_error()); } $query = 'SELECT niks, emails, teksts, datums, id FROM test'; $result = mysql_query($query); if (!$result) { die('Query failed: ' . mysql_error()); } /* fetch rows in reverse order */ for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) { if (!mysql_data_seek($result, $i)) { echo "Cannot seek to row $i: " . mysql_error() . "\n"; continue; } if (!($row = mysql_fetch_assoc($result))) { continue; } echo $row['id'] . ' ' . $row['niks'] . ' ' . $row['emails'] . ' ' . $row['teksts'] . ' ' . $row['datums'] ."<br />\n"; } mysql_free_result($result); ?> Link to comment Share on other sites More sharing options...
Grey_Wolf Posted November 30, 2005 Report Share Posted November 30, 2005 (edited) marnix --> tieshi taa arii ir kaa tu uzrakstiji :) $niks=$row['niks']; bet tu tachu varii arii izmantot to pashu $row['niks'].... $row shajaa gadijumaa ir masiivs... nav obligaati rakstit $row var arii $bla_bla ;) edit: ----- $query='SELECT * FROM tabula WHERE ............ $result= mysql_query($query); $num_results=mysql_num_rows($result); if ($num_results !=0) { for ($i=0; $i<$num_results; $i++) { $row_bla_bla=mysql_fetch_array($result); // izvadam & apstradajam datus echo $row_bla_bla['kautkas']; } } Edited November 30, 2005 by Grey_Wolf Link to comment Share on other sites More sharing options...
rpr Posted November 30, 2005 Report Share Posted November 30, 2005 (edited) peec query raksti uzreiz while ($row = mysql_fetch_assoc($result )) { } liekas darbiibas sanaak, ja tu veic siik un peec tam veel fetch, visu var panaakt ar vienu fetch, palasi manuaali: http://lv2.php.net/manual/en/function.mysql-fetch-assoc.php Edited November 30, 2005 by rpr Link to comment Share on other sites More sharing options...
john.brown Posted December 3, 2005 Report Share Posted December 3, 2005 Un ja gribi tomēr to $row['nick'] dabūt kā $nick, tad pēc fetch taisi extract($row). Tas savietos visu masīvu mainīgajos ar atslēgu nosaukumiem. Link to comment Share on other sites More sharing options...
Recommended Posts