<?php mysql_select_db('haberler' ,mysql_connect('localhost','root','')) or die(mysql_error()); $sayfa = intval($_GET['sayfa']); $toplam = mysql_num_rows(mysql_query("select * from haberler")); $limit = 5; $goster = $sayfa * $limit - $limit; $query = mysql_query("select * from haberler limit $goster,$limit"); while($row = mysql_fetch_array($query)){ echo 'span class="haber">'.$row['haberler'].'</span>'; } ?> this code gets the error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pagination\index.php on line 10 how to fix it please help! how can i fix that arror? please help!
Means your query failed. You need to error out the query and see what's the problem. Replace: $query = mysql_query("select * from haberler limit $goster,$limit"); PHP: with if(!$query = mysql_query("select * from haberler limit $goster,$limit")) { die(mysql_error()); }; PHP:
im pretty sure that your echo line needs some tweaking echo "span class=\"haber\">" . $row['haberler'] . "</span>"; PHP: i couldnt see any use for this: $toplam = mysql_num_rows(mysql_query("select * from haberler")); PHP: perhaps just comment it out while you work on it. try commenting out sayfa and replace it with sayfa = 5 (or other fixed number) just makes sure that it has a variable attached. or replace the get sayfa line with: $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa']; PHP:
@matt_62;your $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa']; code line solved this error: Notice: Undefined index: sayfa in C:\xampp\htdocs\pagination\index.php on line 3 , but real problem is with while ($row = mysql_fetch_array($query)) code line.PHP notices me by this code line, this code line 10.
@jestep your proposal caused a new error that is: 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 '-5,5' at line 1
sadly sql is not my strong point, in fact ive never seen or heard of "limit" before. If this doesnt help you then your on your own. But i think you might have your database name, table name as well as the field names confused. If this helps you let me know, if it doesnt then im unable to help you. <?php // get sayfa $sayfa= (!isset($_REQUEST['sayfa']) || !ctype_digit($_REQUEST['sayfa'])) ? 0 : $_REQUEST['sayfa']; $limit = 5; //get connection details include("mysqlconnection.php"); // save your connection details in here $mysqli = mysqli_connect($host, $user, $pwd); if (!$mysqli) { die('Could not connect: ' . mysql_error()); } mysqli_select_db($db, $mysql); $query = mysqli_query("select * from TABLENAME_NOT_DATABASE_NAME where TABLENAME.FIELD_NAME < '$goster' and TABLENAME.FIELD_NAME > '$limit'"); $result = mysqli_query($mysqli, $query); while($row=mysqli_fetch_array($result)) { print "testing";} ?> //save these details under mysqlconnection.php <?php // this just makes it easy to modify the connection details site wide if details change $host ="localhost"; $user ="root"; $pwd =""; $db ="haberler"; ?> PHP:
thank you very much all of you, i have solved the problem. i realised not set the code if(!$sayfa) $sayfa = 1; in the string. but i learnt lots of your replays...