-1

Hi need help with this code. i get a the error msg

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result

but dont know were to change. my connection is fine????

<?php 
  include ("connect.php");

// max display per page

$per_page = 5;

// get start variable

$start = $_GET ['start'];

// count record

$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats"));

//count max pages

$max_pages = $record_count / $per_page; // may come out as a decimal

if (!start)

  $start = 0;

// display data
$get = mysql_query("SELECT * FROM flats LIMIT $start, $per_page");
 
   while ($row = mysql_fetch_assoc($get))
   
 {
 
  // get data 

   $select= $row['type'];
   $title= $row['title'];
   $location= $row['location'];

    echo "<div><b>$title</b></div>";
    echo "<br>";
    echo "$select";
    echo "<br>";
    echo "$rent";
    echo "<br>";
    echo "$location";
}
?>

Edited by __avd: Use [code] tags to wrap source code.

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by cwarn23
0

i need help with one more thing. My pagination script is working fine when its outside the html code but when i put it inside the table it does not show the Prev 1 2 3 4 next. and also it does not respond to

(mysql_query("SELECT * FROM flats ORDER BY date_posted DESC"));

instead it just display the data order by who posted first rather then last posted.

any ide? thanks

0

i need help with one more thing. My pagination script is working fine when its outside the html code but when i put it inside the table it does not show the Prev 1 2 3 4 next. and also it does not respond to

(mysql_query("SELECT * FROM flats ORDER BY date_posted DESC"));

instead it just display the data order by who posted first rather then last posted.

any ide? thanks

to display data order by last post use this query

"SELECT * FROM flats ORDER BY date_posted asc";

and inside which table you putting this code, post that part of the code too.

0
<table width="487" height="672"  border="1" align="left" cellpadding="3" cellspacing="3" background="/bgtr.gif">
                <tr align="center" valign="middle"> 
                  <td width="23%" height="28" bgcolor="#FFFFFF"> <h3 align="center">Available 
                     </h3></td>
                </tr>
                <tr align="center" valign="middle"> 
                  <td height="626" align="left" valign="top" bgcolor="#FFFFFF"> 
                             

<?php

include ("connect.php");


// max display per page

$per_page = 50;

// get start variable

$start = $_GET ['start'];

// count record

$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats ORDER BY date_posted ASC")); 

//count max pages

$max_pages = $record_count / $per_page; // may come out as a decimal

if (!$start)

  $start = 0;

// display data
$get = mysql_query("SELECT * FROM flats LIMIT $start, $per_page");
 
   while ($row = mysql_fetch_assoc($get))
   
 {
 
  // get data 

   $select= $row['type'];
   $title= $row['title'];
   $location= $row['location'];
  

    echo "<div><b>$title</b></div>";
    echo "<br>";
    echo "$select";
    echo "<br>";
    echo "$rent";
    echo "<br>";
    echo "$location";
 

}

// setup the prev and next variables

$prev = $start - $per_page; 

$next = $start + $per_page;

//show prev button

if (!($start<=0)) 

  echo " <a href='pagination.php?start=$prev'> << Prev </a> ";

//show page numbers

// set variable for first page

$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{

 if ($start!=$x)
   
  echo " <a href='pagination.php?start=$x'>$i |</a> ";

else 
  echo " <a href='pagination.php?start=$x'><b> $i|</b></a> ";

$i++;

}

//show next button

 if (!($start>=$record_count-$per_page))
 echo " <a href='pagination.php?start=$next'> Next >></a> "; 


?>

                  </td>
                </tr>
              </table>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Try replacing the count section of the code with this:

// count record

$record_count = mysql_num_rows (mysql_query("SELECT * FROM flats")); 

//count max pages

$max_pages = ceil($record_count / $per_page); // may come out as a decimal

That should fix a major bug.

0

hi, the changes didn't make any difference. my problem is that the code wont display the data from the last sender DESC and that the prev 1234 next is not showing when its within a html table. i tried your suggestion but no luck. any ide

0
$get = mysql_query("SELECT * FROM flats LIMIT $start, $per_page");

Replace the above with something like the below.

$get = mysql_query("SELECT * FROM flats ORDER BY date_posted DESC LIMIT $start, $per_page");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.