reGative Posted December 19, 2009 Report Share Posted December 19, 2009 Mans kods ir šāds: <?php $con = mysql_connect("serveris","username","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM news"); while($row = mysql_fetch_array($result)) { echo $row['post-content'] . " " . $row['post-title']; echo "<br />"; } mysql_close($con); ?> ok, bet pārlūkos rāda šādu tekstu: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\rG_CMS\index.php on line 12 Es nejēdzu, kur ir kļūda. PHP programmēšanā esmu iesācējs, pamatus zinu, vēlos iemācīties datus no datubāzes dabūt pārlūkā. Quote Link to comment Share on other sites More sharing options...
false Posted December 19, 2009 Report Share Posted December 19, 2009 Pameiģini šita <?php mysql_connect("serveris","username","pass"); mysql_select_db("db"); $select = mysql_query("SELECT * FROM news") or die(mysql_error()); while($row = mysql_fetch_array($select)){ echo $row['post-content']; echo $row['post-title']; } ?> ja radis to pašu, tad tev taja dātubāzē nav tadu tabulu vai arī vispar nav tadas dātubāzes. Quote Link to comment Share on other sites More sharing options...
404 Posted December 19, 2009 Report Share Posted December 19, 2009 (edited) Netiek pārbaudīts,vai kverijs ir veiksmīgs un vispār kaut ko atgriež.Jēdzīgāk būtu rakstīt: if($result = mysql_query("SELECT * FROM news")) { if(!mysql_num_rows($result)>0) echo 'Ziņu nav'; else { while($row = mysql_fetch_array($result)) { echo $row['post-content'] . " " . $row['post-title']; echo "<br />"; } } } else echo mysql_error(); Edit: iepriekšējais jau pasteidzās to pašu uzrakstīt:) Edited December 19, 2009 by 404 Quote Link to comment Share on other sites More sharing options...
reGative Posted December 19, 2009 Author Report Share Posted December 19, 2009 Izlaboju uz false piemēru, tagad - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'news' at line 1 P.S. Slēpju īstos nosaukumus, index.php failā protams, ka norādu īsto :) Quote Link to comment Share on other sites More sharing options...
waplet Posted December 19, 2009 Report Share Posted December 19, 2009 `news` pamēģini Quote Link to comment Share on other sites More sharing options...
reGative Posted December 19, 2009 Author Report Share Posted December 19, 2009 Visādas pēdiņas mēģināju, nekas nesanāk. Redzams no manis nekāds koderis neiznāks... Quote Link to comment Share on other sites More sharing options...
waplet Posted December 19, 2009 Report Share Posted December 19, 2009 hmm.. izskatās jau tīrs tas kods, pat nezinu, kur varētu būt problēma.. kas ir ja to mysql query iznes ārpus if'a? bet nedomāju, ka tas kaut ko palīdzes.. bet teoerētiski, tev ir tā tabula news? Quote Link to comment Share on other sites More sharing options...
reGative Posted December 19, 2009 Author Report Share Posted December 19, 2009 Izmēģināju abus skriptus, izmēģināju jūsu piedāvājums, nekas nestrādā. Īstenībā db sauc blogs un db tabla sauc par wp-posts. Tas ir jūsu zinašanai. Quote Link to comment Share on other sites More sharing options...
waplet Posted December 19, 2009 Report Share Posted December 19, 2009 un SELECT * FROM `wp-posts` nestrādā? Quote Link to comment Share on other sites More sharing options...
reGative Posted December 19, 2009 Author Report Share Posted December 19, 2009 Nē, nestrādā, tas pats errors saistībā ar sintaksi. Quote Link to comment Share on other sites More sharing options...
briedis Posted December 19, 2009 Report Share Posted December 19, 2009 Pareizo datubāzi izvēlējies? Quote Link to comment Share on other sites More sharing options...
waplet Posted December 19, 2009 Report Share Posted December 19, 2009 caur piemēram phpmyadmin arī to pašu rāda? kko tādu es redzu pirmo reizi Quote Link to comment Share on other sites More sharing options...
reGative Posted December 20, 2009 Author Report Share Posted December 20, 2009 Labrīt. Vakar biju noguris.... Tātad pievienoju SELECT * FROM `wp-posts` LIMIT 0, 30 Bet tagad nekāda satura nav, bet phpmyadmin ir saturs. Quote Link to comment Share on other sites More sharing options...
2easy Posted December 20, 2009 Report Share Posted December 20, 2009 oo, false iesaka debugošanu un vēl parāda praktisku piemēru, kā to darīt! tiešām prieks redzēt, ka tu progresē ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.