By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Page don't load - using odbc and Access db

P: 6
I'm using ODBC to read a office access db

the db have almost 10,000 rows so I want to split it into pages

The first page load nice and quick, but in other pages i get:

Expand|Select|Wrap|Line Numbers
  1. Maximum execution time of 30 seconds exceeded in c:\apache\htdocs\eyal\new.php on line 100
the line 100 is the odbc_exec command.

in the top of the page i get:

Expand|Select|Wrap|Line Numbers
  1. Warning: Use of undefined constant id - assumed 'id' in c:\apache\htdocs\eyal\new.php on line 7
  2. Warning: Use of undefined constant pname - assumed 'pname' in c:\apache\htdocs\eyal\new.php on line 8
  3. Warning: Use of undefined constant lname - assumed 'lname' in c:\apache\htdocs\eyal\new.php on line 9
  4. Warning: Use of undefined constant addr - assumed 'addr' in c:\apache\htdocs\eyal\new.php on line 10
  5. Warning: Use of undefined constant city - assumed 'city' in c:\apache\htdocs\eyal\new.php on line 11
  6. Warning: Use of undefined constant phone - assumed 'phone' in c:\apache\htdocs\eyal\new.php on line 12
  7. Warning: Use of undefined constant cphone - assumed 'cphone' in c:\apache\htdocs\eyal\new.php on line 13
  8. Warning: Use of undefined constant jdate - assumed 'jdate' in c:\apache\htdocs\eyal\new.php on line 14
the lines:
Expand|Select|Wrap|Line Numbers
  1.   $fields = array(id => "מספר כרטיס",
  2.                   pname => "שם פרטי:",
  3.                   lname => "שם משפחה:",
  4.                   addr => "כתובת:",
  5.                   city => "עיר מגורים:",
  6.                   phone => "מספר טלפון:",
  7.                   cphone => "מספר פלאפון:",
  8.                   jdate => "תאריך הצטרפות:");
  9.  
the main of my code:

Expand|Select|Wrap|Line Numbers
  1. switch ($do) {
  2.     case "list":
  3.         if ($page > 0) {
  4.             $npage = $page + 1;
  5.             $ppage = $page - 1;
  6.         }
  7.         else {
  8.             $page = 0;
  9.             $npage = 1;
  10.         }
  11.         $gpage = $page * 50;
  12.         print("<table dir=\"rtl\" cellspacing=0 cellpadding=5>
  13.                <tr dir=\"rtl\">");
  14.         foreach ($fields as $key => $value) {
  15.             $value = str_replace(":", " ", $value); 
  16.             print("<th class=main>$value</th>");
  17.         }
  18.         print("<th class=endmain>ניהול</th>
  19.                </tr>");
  20.         if ($gpage == 0) {
  21.             $sql_query = "SELECT TOP 50 * FROM tbl_clients";
  22.         }
  23.         else {
  24.             $sql_query = "SELECT TOP 50 * FROM tbl_clients where ( ID NOT IN ( SELECT TOP $gpage id FROM tbl_clients ORDER BY id ASC ) ) ORDER BY id ASC";
  25.         }
  26.         $do_query = odbc_exec($conn, $sql_query);                               
  27.         while (odbc_fetch_row($do_query)) {
  28.             print("<tr>");
  29.             foreach ($fields as $key => $value) {
  30.                 $text = odbc_result($do_query,$key);
  31.                 if ($key == "id") { $text = round($text); }
  32.                 if($key == "jdate") { $text = ereg_replace(" 00:00:00" , "", $text); }
  33.                 print("<td class=main>&nbsp;$text</td>");
  34.             }
  35.             print("<td class=endmain>&nbsp;" . dolink("$_SERVER[PHP_SELF]?do=edit", "עריכה"));
  36.             print("</tr>");  
  37.         }
  38.         print("<tr>");
  39.         if (empty($page) OR !isset($page)) {
  40.             $form = $_SERVER['QUERY_STRING'];
  41.             if ($page == 0) {
  42.                 $form = ereg_replace("page=0", "page=$npage", $form);
  43.  
  44.             }
  45.             else {
  46.                 $form .= "&page=1";
  47.             }
  48.             echo $form;
  49.             print("<td>");
  50.             pp($form, "next");
  51.             print("</td>");
  52.         }
  53.         else {
  54.             if ($page > 0) {
  55.                 $form = $_SERVER[QUERY_STRING];
  56.                 $form = ereg_replace("page=$page", "page=$ppage", $form);
  57.                 print("<td>");
  58.                 pp($form, "prev");
  59.                 print("</td>");
  60.             }
  61.             print("<td>&nbsp;</td>");
  62.             if (($page > 0) AND ($page < $count)) {
  63.                 $form = $_SERVER[QUERY_STRING];
  64.                 $form = ereg_replace("page=$page", "page=$npage", $form);
  65.                 print("<td>");
  66.                 pp($form, "next");
  67.                 print("</td>");
  68.             }
  69.         }
  70.         print("</tr>");
  71.         doexit();                   
  72. }
  73.  
Help

Thanks :)
Oct 17 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
You could set the time limit of a page so that your script doesn't time out.
Oct 17 '08 #2

P: 6
That helps, thanks.

But why is it taking so long (about 3 min) for the page to load?

I don't think it's my comp... duel core with 2gb ram...

maybe something in the code?
Oct 17 '08 #3

Atli
Expert 5K+
P: 5,058
Hi.

First, your array keys are defined incorrectly. Assuming they are meant to be strings, they should be quoted.
Expand|Select|Wrap|Line Numbers
  1. // This is incorrect. It will try to load the value for the
  2. // constant named id, but if it fails to find it, it will
  3. // assume it was meant to be a string and show a warning.
  4. $arr = array(id => 'some value');
  5.  
  6. // This is how it should be done
  7. $arr = array('id' => 'some value'); //Correct
  8.  
As to the execution time, I would assume it is database related. The PHP code itself should not take anywhere near that long to execute.
The SQL query, however, could be taking some time on a large table. Especially if that table was not designed for such a query on a large amount of data.

How to fix such a problem I do not know. I don't know enough about Access to really know that. Maybe it has something to do with the sub-query? I know they can cause performance issues on other SQL servers.
Oct 18 '08 #4

P: 6
Thanks, it solved my array error.

Do you know another way for me to use instead of sub-query?

I searched google alot to find this solution for paging in mssql.
Oct 18 '08 #5

P: 6
Okay do I decided to do the page system the "long" way: selecting all the db and just printing the "right" page.

The problem now is that It's skipping rows (id 1, 3, 5, 7 and so on)

Here's the code:

Expand|Select|Wrap|Line Numbers
  1.         if ($page > 0) {
  2.             $npage = $page + 1;
  3.             $ppage = $page - 1;
  4.         }
  5.         else {      
  6.             $page = 0;
  7.             $npage = 1;
  8.         } 
  9.         $gpage = $page * 50;
  10.         print("<table dir=\"rtl\" cellspacing=0 cellpadding=5>
  11.                <tr dir=\"rtl\">");
  12.         foreach ($fields as $key => $value) {
  13.             $value = str_replace(":", " ", $value); 
  14.             print("<th class=main>$value</th>");
  15.         }
  16.         print("<th class=endmain>ניהול</th>
  17.                </tr>");
  18.         $sql_query = "SELECT * FROM tbl_clients ORDER BY id ASC";
  19.         $do_query = odbc_exec($conn, $sql_query);
  20.         $target = $gpage + 50;
  21.         $row_count = 0;
  22.         while (odbc_fetch_row($do_query)) {
  23.             if ($row_count < $gpage) {
  24.                 $row_count++;
  25.                 continue;
  26.             }
  27.             else {
  28.                 if ($gpage < $target) {
  29.                     print("<tr>");
  30.                     foreach ($fields as $key => $value) {
  31.                         $text = odbc_result($do_query,$key);
  32.                         if ($key == "id") { $text = round($text); }
  33.                         if($key == "jdate") { $text = ereg_replace(" 00:00:00" , "", $text); }
  34.                         print("<td class=main>&nbsp;$text</td>");
  35.                     }
  36.                     print("<td class=endmain>&nbsp;" . dolink("$_SERVER[PHP_SELF]?do=edit", "עריכה"));
  37.                     print("</tr>");
  38.                     $gpage++;
  39.                 }
  40.                 else if ($gpage > $target) {
  41.                     break;
  42.                 }
  43.             }
  44.         }
  45.  
Why?

Thanks :)
Oct 20 '08 #6

Post your reply

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