Browsing results, a little preoblem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Igguana
Forum Commoner
Posts: 36
Joined: Tue Mar 11, 2003 1:08 pm

Browsing results, a little preoblem.

Post by Igguana »

I have a database and I'm trying to show the results of a search grouped in the amount of five, and to go the next five or come back to the previous.
I'm using "LIMIT" in the query for doing this and I think I will arrange it, but I have a mysql_num_rows function there that is responsible to show the total amount of coincidences, and by this way, the variable returns the values asigned to LIMIT, not the total one.
<?php
$base="bla";
$tabla="DatosInmueble";
$conexion = mysql_connect(bla) or die(mysql_error());
mysql_select_db($base,$conexion) or die(mysql_error());

$clauses = array();
if (isset($_POST['envio1'] ) && $_POST['envio1'] != -1)
$clauses[] = 'Modo='.(int)$_POST['envio1'];
if (isset($_POST['envio2'] ) && $_POST['envio2'] != -1)
$clauses[] = 'Localidad='.(int)$_POST['envio2'];
if (isset($_POST['envio3'] ) && $_POST['envio3'] != -1)
$clauses[] = 'Tipo='.(int)$_POST['envio3'];
if (isset($_POST['envio4'] ) && $_POST['envio4'] != -1)
$clauses[] = 'Habitaciones='.(int)$_POST['envio4'];
if (isset($_POST['envio5'] ) && $_POST['envio5'] != -1)
$clauses[] = 'Precio<='.(int)$_POST['envio5'];

$query = "SELECT * FROM $tabla LIMIT 0,5";
if (count($clauses) > 0)
$query .= ' WHERE '.join('AND ', $clauses);
$pegar=mysql_query($query, $conexion) or die($query.' :'.mysql_error());
$coincidencias=mysql_num_rows($pegar);
?>
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

In order to get the total amount of possible rows from the table, you're going to have to perform a separate query:

SELECT COUNT(*) FROM tabla

This will return the total number of rows in the table ... so you can do this before or after you want to grab only 5 rows from the table.
Post Reply