Jump to content

Pagination Question


mymate

Recommended Posts

Hey, i need some help with my pagination; im creating a directory of employees. there is a very long list of about 150 of them, there are 3 offices. In my sql table i have named these offices; location1, location2, location3

I now want so that when i enter
domain.com/employees.php=location?=location1

it displays the list of employees in that location in a table,

i have been trying to modify this code to do it, but my php knowlegde is very limited,

thanks in advance





[code]

<?php

include('mysql_connect.php');
if ((isset($_GET['id'])) && (is_numeric($_GET['id'])) ) {
$id = $_GET['id'];
}

$query = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);

$proid = $row['0'];
$name = $row['1'];
$title = $row['2'];
$location = $row['3'];
$exn = $row['4'];
$exdd = $row['5'];
$email = $row['6'];
$ext = $row['7'];

echo '
'.$proid.' '.$name.' '.$title.' '.$location.' '.$exn.' '.$exdd.' '.$email.' '.$ext.'
';


?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/25916-pagination-question/
Share on other sites

Use a url like this:
domain.com/employees/php?location=location1

Then build the query in your code like this:
[code]
$query = "SELECT * FROM employees WHERE id=$id";
if (isset ($_GET['location']) && $_GET['location']) {
$query .= ' AND location="' . $_GET['location'] . '"';
}
[/code]

regards
pnj
Link to comment
https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118352
Share on other sites

Give this a try...

[code]<?php
// connect to db
include('mysql_connect.php');

// check the url for a location ID
if (isset($_GET['location'])){
  $loc = $_GET['location'];
}
else {
  // set a default location if one wasn't specified
  $loc = "Location1";
}

// query the database
$query = "SELECT * FROM employees WHERE location = '$loc'";
$result = mysql_query($query);

// loop through each record
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  extract($row); // import the column names into the namespace
  echo "$proid, $name, $title, $location, $exn, $exdd, $email, $ext<br>\n";
}
?>[/code]

Then call this with something like [color=green]employees.php?location=Location1[/color]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118360
Share on other sites

Try changing this:

[code]// set a default location if one wasn't specified
$loc = "Location1";[/code]

To this:

[code]// set a default location if one wasn't specified
$loc = "Location_";[/code]

In MySQL the underscore ( _ ) acts as a wild card for a single character.  You'll also need to change the query to look loke this:

[code]$query = "SELECT * FROM employees WHERE location LIKE '$loc'";[/code]

Regards
Huggie

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118474
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.