473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

New member stuck in write php script

2
Hi friend, I am new in this area.
Hope members can help me on my script below.
I want to create Previous and Next button but it runs until maximum execution time. Help me
[php]
<?php #script view_users.php pg 279

//This script retrieves all the records from the register table.

//This new version allows the results to be sorted in different ways.

//Page header.
echo '<h1 id="mainhead">Registered Projects</h1>';

//cONNECT TO THE DATABASE.
require_once 'Connect/mysql_connect.php';

//Number of records to show per page
$display = 5;


//Determine how many pages there are.
if (isset($_GET['np'])) { //Already been determined.

$num_pages = $_GET['np'];

} else { //Need to determine.

//Count the number of record.
$query = "SELECT serial,date, department, user_id, email, project, description FROM register";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row['0'];

//Calculate the number of pages.
if ($num_records > $display) { //More than 1 page.

$num_pages = ceil ($num_records/$display);

} else {

$num_pages = 1;

}

} //End of np IF.

//Determine where in the database to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];

} else {

$start = 0;
}


//Default column links

$link1 = "{$_SERVER['PHP_SELF']}?sort=dt";
$link2 = "{$_SERVER['PHP_SELF']}?sort=dpmt";
$link3 = "{$_SERVER['PHP_SELF']}?sort=usr";
$link4 = "{$_SERVER['PHP_SELF']}?sort=em";
$link5 = "{$_SERVER['PHP_SELF']}?sort=pj";


//Determine the sorting order.
if (isset($_GET['sort'])) {


//Use existing sorting order.

switch ($_GET['sort']) {

case 'dt':
$order_by = 'date ASC';
link1 == "{$_SERVER['PHP_SELF']}?sort=adt";
break;
case 'adt':
$order_by = 'date DESC';
link1 == "{$_SERVER['PHP_SELF']}?sort=dt";
break;

case 'dpmt':
$order_by = 'department ASC';
link2 == "{$_SERVER['PHP_SELF']}?sort=adpmt";
break;
case 'adpmt':
$order_by = 'department DESC';
link2 == "{$_SERVER['PHP_SELF']}?sort=dpmt";
break;

case 'usr':
$order_by = 'user_id ASC';
link3 == "{$_SERVER['PHP_SELF']}?sort=ausr";
break;
case 'ausr':
$order_by = 'user_id DESC';
link3 == "{$_SERVER['PHP_SELF']}?sort=usr";
break;

case 'em':
$order_by = 'email ASC';
link4 == "{$_SERVER['PHP_SELF']}?sort=aem";
break;
case 'aem':
$order_by = 'email DESC';
link4 == "{$_SERVER['PHP_SELF']}?sort=em";
break;

case 'pj':
$order_by = 'project ASC';
link2 == "{$_SERVER['PHP_SELF']}?sort=apj";
break;
case 'apj':
$order_by = 'project DESC';
link2 == "{$_SERVER['PHP_SELF']}?sort=pj";
break;

default:
$order_by = 'email
DESC';
break;

}


//$sort will be appended to the pagination links.

$sort = $_GET['sort'];

} else { //use the default sorting order.

$order_by = 'email ASC';
$sort = 'aem';

}


//Make the query.

$query = "SELECT date, department, user_id, email, project, description FROM register ORDER BY $order_by LIMIT $start, $display";
$result = @mysql_query ($query);


//Table header

echo '<table align="center" cellspacing="0"
cellpadding="5">

<tr>

<td align="left"><b><a href="' .
$link1 . '">Date</a></b></td>

<td align="left"><b><a href="' .
$link2 . '">Department</a></b></td>

<td align="left"><b><a href="' .
$link3 . '">User</a></b></td>

<td align="left"><b><a href="' .
$link4 . '">Email</a></b></td>

<td align="left"><b><a href="' .
$link5 . '">Project</a></b></td>

<td align="left"><b>Edit</b></td>
<td align="left"><b>Delete</b>
</td>
</tr>
';


//Fetch and print all the records.
$bg = '#eeeeee'; //set the background color.

while ($row = mysql_fetch_array($result,
MYSQL_ASSOC)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' :
'#eeeeee'); //switch the background color.

echo '<tr bgcolor="' . $bg . '">


<td align="left">' . $row['date'].'</td>
<td align="left">' . $row['department'].'</td>
<td align="left">' . $row['user_id'].'</td>
<td align="left">' . $row['email'].'</td>
<td align="left">' . $row['project'].'</td>

<td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td>
<td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td>
</tr>
';
}

echo '</table>';

mysql_free_result ($result); //Free up the resources.


mysql_close(); //Close the database connection.


//Make the link to other pages, if necessary

if ($num_pages > 1) {

echo '<br /><p>';

//Determine what page the script is on.
$current_page = ($start/$display) + 1;

//If it's not the first page, make a Previous button.

if ($current_page != 1) {
echo '<a href="sortable_display.php?s='.
($start - $display) . '&np=' .
$num_pages . '&sort=' . $sort .
'">Previous</a>';

}

//Make all the numbered pages.

for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="sortable_display.php?s='
. (($display * ($i - 1))) .
'&np=' . $num_pages . '&sort=' ,
$sort . '">' . $i .'</a> ';

} else {

echo $i . '';
}

}

//If it's not the last page, make a Next button.

if ($current_page != $num_pages) {
echo '<a href="sortable_display.php?s='
. ($start + $display) . '&np=' .
$num_pages . '&sort=' . $sort .
'">Next</a>';

}

echo '</p>';


} //End of links section

?>[/php]
Dec 13 '06 #1
2 1671
MMcCarthy
14,534 Expert Mod 8TB
Welcome to thescripts Azmiza.

Please check out our PHP forum.

Mary
Dec 15 '06 #2
ronverdonk
4,258 Expert 4TB
What output does your script produce? Anything?

Next time, enclose your code within code, php or html tags. That makes it a lot easier to read for our members and they will be more inclined to help you.
Read the Posting Guidelines at the top of this forum before you post.

Ronald :cool:
Dec 18 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andy Norman | last post by:
I have a strange problem. When I try to call the input property of the MSXML processor object from VBScript in an ASPX page I get the error "Member not found". The same code (with a few "set"...
15
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes...
30
by: Joost Ronkes Agerbeek | last post by:
Why is it allowed in C++ to call a static member function of an object through an instance of that object? Is it just convenience? tia, Joost Ronkes Agerbeek
3
by: Québec | last post by:
Hi to the excellent newsgroup, I got a script that works on pc with Opera, IE and Netscape. But some mac users told me they could not access my web site at-- http://jeanpierredaviau.com where...
8
by: Alan Silver | last post by:
Hello, I'm trying to write a simple user control as an exercise (and 'cos it might be useful). I am trying to do a simple date picker, which consists of three drop down lists, one for the day,...
2
by: PJ | last post by:
Hi I was developing a Class for skinning an application. IN order to read the image file dynamically I used System.Drawing.Image.FromFile("..."). Strangely VS 2003 returns an error saying that...
3
by: Dilip | last post by:
I am stuck with a syntactical issue and would appreciate some help: I have a class with a templated mem fn like so: class A { }; template<typename Ret, typename P1, Ret (A::*fp)(P1*)>...
11
by: fjm | last post by:
Hello all. I used to have hair, but now I don't. We can thank OOP for this. :) I have an employee class and a second script where all of my calls are for the employee class. I need to build...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.