sandrulis Posted July 22, 2013 Report Share Posted July 22, 2013 Sveiki, neliela problēma saistībā ar ierakstu ielādēšānu (kaut kas līdzīgs kā Twitter). ar šo kodu viss ir kārtībā, līdz brīdim kad nāk palīgā .htaccess fails ar mod_rewrite funkciju. kas tieši ir pa vainu? kas jādara lai lai viss būtu ok? :) PHP: <? print "<ol id='updates'>"; $result=mysql_query("SELECT * FROM articles ORDER BY id ASC LIMIT 10"); while($row = mysql_fetch_array($result)) { $article_id=$row['id']; $message=$row['question']; print "<li>{$message}</li>"; } print "</ol>"; print "<div id='more'><a id='{$article_id}' class='load_more' href='#'>more</a></div>"; ?> Javascript: $(function() { $('.load_more').live("click",function() { var last_article_id = $(this).attr("id"); $.ajax({ type: "POST", url: "load_more.php", data: "last_article_id="+ last_article_id, beforeSend: function(){$('a.load_more').html('<img src="loading.gif" />');}, success: function(html) { $("#more").remove(); $("ol#updates").append(html); } }); return false; }); }); load_more.php: <? include('config.php'); if(isset($_POST['last_article_id']) &&is_numeric($_POST['last_article_id'])) { $article_id=$_POST['last_article_id']; $result=mysql_query("SELECT * FROM articles WHERE id < '{$article_id}' ORDER BY id ASC LIMIT 10"); while($row = mysql_fetch_array($result)) { $last_article_id=$row['id']; $message=$row['question']; print "<li>{$message}</li>"; } if(mysqli_num_rows($result)==1) { print "<div id='more'>"; print "<a id='{$msg_id}' class='load_more' href='#'>more</a></div>"; } else {print "<div id='more'><a class='load_more' href='#'>No More Posts</a></div>";} } ?> Link to comment Share on other sites More sharing options...
jurchiks Posted July 22, 2013 Report Share Posted July 22, 2013 (edited) mysql_query fuck that shit... Un vispār, tu tā arī nepateici, kāda konkrēti ir problēma? Kāds tur sakars .htaccess rewraitam? P.S. is_numeric($_POST['last_article_id']) -> ctype_digit("{$_POST['last_article_id']}") Pieredze rāda, ka GET un POST requestos padodot ciparus, saņēmēja galā tie tiek izparsēti kā stringi. is_numeric() čeko datu tipu, nevis saturu. Edited July 22, 2013 by jurchiks Link to comment Share on other sites More sharing options...
sandrulis Posted July 22, 2013 Author Report Share Posted July 22, 2013 Un vispār, tu tā arī nepateici, kāda konkrēti ir problēma? Kāds tur sakars .htaccess rewraitam? Viss strādā un ielādē rakstus, līdz pievieno .htaccess funkciju, kas pievieno šo funkciju rāda ka visu laiku lādē un neko neielādē Link to comment Share on other sites More sharing options...
jurchiks Posted July 22, 2013 Report Share Posted July 22, 2013 (edited) kādu nafig .htaccess funkciju? Še, kods, kurš strādās, ja iemācīsies izmantot mysqli. if(isset($_POST['last_article_id']) && ctype_digit("{$_POST['last_article_id']"})) { $last_article_id = $_POST['last_article_id']; // $dbcon = new mysqli(...); // uztaisi kaut vai kaut kādu inkludējamu failu, kurā šis tiek izveidots $pstmt = $dbcon->prepare('SELECT id, question FROM articles WHERE id < ? # baigās aizdomas, ka bija domāts > ? ORDER BY id ASC LIMIT 10'); $pstmt->bind_param('i', $last_article_id); $pstmt->execute(); $pstmt->bind_result($id, $question); while ($pstmt->fetch()) { $last_article_id = id; echo '<li>', $question, '</li>'; } // viss, kas seko zemāk, ir galīgs autisms un neiederās šajā vietā, jo jQuery appendo šī faila returnoto saturu OL tagam, bet OL tagā nedrīkst pa tiešo būt DIV bloks echo '<div id="more">'; if ($pstmt->num_rows > 0) { echo '<a class="load_more" href="#" id="', $last_article_id, '">More</a>'; } else { echo '<a class="load_more" href="#">No More Posts</a>'; } echo '</div>'; $pstmt->free_result(); $pstmt->close(); } Bet vispār tev tas kods ir drausmīgs, daudz vietu, kur kaut kas varētu nofeilot. Steidzami vajag kaut kur iet pamācīties kārtīgi, ar šitādu skillu tevi neviens normāls uzņēmējs neņems darbā. Edited July 22, 2013 by jurchiks Link to comment Share on other sites More sharing options...
sandrulis Posted July 22, 2013 Author Report Share Posted July 22, 2013 (edited) kādu nafig .htaccess funkciju? mod_rewrite ja linkā ir piem: ?action=kautkas&id=kkads_cipars visss strādā, bet ja lietot mod_rewrite un linku uztaisa ar /kautkas/kkads_cipars neko neielādē Edited July 22, 2013 by sandrulis Link to comment Share on other sites More sharing options...
jurchiks Posted July 22, 2013 Report Share Posted July 22, 2013 (edited) Tad rewraitā ir vaina, nevis kodā. Rewraits nemaina POST variabļus (cerams, hz kas tev tur ir), requestam vienalga vajadzētu aiziet uz gala skriptu. Edited July 22, 2013 by jurchiks Link to comment Share on other sites More sharing options...
Klez Posted July 22, 2013 Report Share Posted July 22, 2013 rewrite rule pareiza? te nav nevienam kristāla bumbas, kuras pasaka, kādas tev rules iekš htaccess Link to comment Share on other sites More sharing options...
sandrulis Posted July 22, 2013 Author Report Share Posted July 22, 2013 (edited) problēma tika atrasta visa vaina bija, nebiju ielicis "/" pie url: javascript: $(function() { $('.load_more').live("click",function() { var last_article_id = $(this).attr("id"); $.ajax({ type: "POST", url: "/load_more.php", data: "last_article_id="+ last_article_id, beforeSend: function(){$('a.load_more').html('<img src="loading.gif" />');}, success: function(html) { $("#more").remove(); $("ol#updates").append(html); } }); return false; }); }); Edited July 22, 2013 by sandrulis Link to comment Share on other sites More sharing options...
Recommended Posts