mymate Posted November 2, 2006 Share Posted November 2, 2006 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, location3I 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]<?phpinclude('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] Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/ Share on other sites More sharing options...
HuggieBear Posted November 2, 2006 Share Posted November 2, 2006 OK, I'm afraid you're quite a way off here, but not so far gone that you can't be helped :)RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118351 Share on other sites More sharing options...
pnj Posted November 2, 2006 Share Posted November 2, 2006 Use a url like this:domain.com/employees/php?location=location1Then 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]regardspnj Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118352 Share on other sites More sharing options...
mymate Posted November 2, 2006 Author Share Posted November 2, 2006 exactly mate, i asumme all the other feilds are irevant at this point? as i want the whole table queried and displayed? Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118353 Share on other sites More sharing options...
pnj Posted November 2, 2006 Share Posted November 2, 2006 not sure i follow the latest question. the query above should get you all the fields for the employees in the specified location...-pnj Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118359 Share on other sites More sharing options...
HuggieBear Posted November 2, 2006 Share Posted November 2, 2006 Give this a try...[code]<?php// connect to dbinclude('mysql_connect.php');// check the url for a location IDif (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 recordwhile ($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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118360 Share on other sites More sharing options...
mymate Posted November 2, 2006 Author Share Posted November 2, 2006 woops - Parse error: parse error, unexpected '{' in C:\webserver\Apache2\htdocs\employees_test.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118363 Share on other sites More sharing options...
HuggieBear Posted November 2, 2006 Share Posted November 2, 2006 I've corrected in the above post, you can try again now.Huggie Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118394 Share on other sites More sharing options...
mymate Posted November 2, 2006 Author Share Posted November 2, 2006 your a legend mate, thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118423 Share on other sites More sharing options...
mymate Posted November 2, 2006 Author Share Posted November 2, 2006 mmm one last question, is it possible to have the default 'location' set to show all employees in the table?[code]else { // set a default location if one wasn't specified $loc = "";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118443 Share on other sites More sharing options...
HuggieBear Posted November 2, 2006 Share Posted November 2, 2006 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]RegardsHuggieRegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118474 Share on other sites More sharing options...
mymate Posted November 2, 2006 Author Share Posted November 2, 2006 got it, heres the code i used [code]else { // set a default location if one wasn't specified $loc = "'*'";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25916-pagination-question/#findComment-118486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.