Page 1 of 1

page turning script error

Posted: Wed Jan 25, 2006 2:45 am
by joecrack
hey guys i have a big problem with my function.
it is supposed to change the site after a certain amount of datasets/rows.
but when i put in more than 23 rows per page it starts with the table headers again instead of a new row.
sometimes it also goes completly nuts and just keeps on printing out datasets without stopping (when you put the rows per page limit on more than 30). but it works fine with everythig under 23. i dont have any idea what it could be. if someone could have a look at it 8) PLEASE

Code: Select all

error_reporting(E_All);
include("connect.php");
  $sqlab = "SELECT sam_date_val.Incdate,sam_date_val.Customernr,sam_date_val.Projnr,sam_bestellung.Area,sam_bestellung.Groupp FROM sam_date_val,sam_bestellung WHERE sam_bestellung.projnr=sam_date_val.projnr AND sam_bestellung.customernr=sam_date_val.customernr ORDER BY customernr";
  mysql_select_db('safe');

   $daten = mysql_query($sqlab) OR die(mysql_error());
   $num = mysql_num_rows($daten);

    $rows_per_page = 23;       // THE LIMIT
    $max_sets = 1000;

if ($num > $max_sets) {
    echo "<br>Too many<br><br>";
    $num = $max_sets;
    }

    for ($i =0; $i<$rows_per_page; $i++) { 
        $mail = @mysql_result($daten,$i, "mail");

        if (isset ($_GET['page'])) {
            $page = $_GET['page'];
            $start=$page * $rows_per_page;
        }
        else {
        $start = 0;
        $page = 0;
        }

        $sqlab = "SELECT sam_date_val.Incdate,sam_date_val.Customernr,sam_date_val.Projnr,sam_bestellung.Area,sam_bestellung.Groupp FROM sam_date_val,sam_bestellung WHERE sam_bestellung.projnr=sam_date_val.projnr AND sam_bestellung.customernr=sam_date_val.customernr ORDER BY customernr LIMIT $start,$Zeilen_pro_Seite";

        $daten = mysql_query($sqlab) OR die(mysql_error());

        $mail = @mysql_result($daten,$i, "mail");
echo "<table border=\"4\", align=\"center\", cellpadding=\"3\", rules=\"all\"><caption style=\"caption-side:top;\"><strong>Present Orders List</strong></caption>\n";
  echo "  <tr>\n";
echo"
<th nowrap>Incoming Date</th>
<th nowrap colspan=\"2\">Project No</th>
<th nowrap>Area</th>
<th nowrap>Group</th>
";
echo "  </tr>\n";

  while ($row = mysql_fetch_row($daten)){
    echo "  <tr>\n";
	echo"
	<td>$row[0]</td>
	<td colspan=\"2\">$row[1]$row[2]</td>";

    for ($i = 3; $i < mysql_num_fields($daten); $i++){
      echo "    <td>$row[$i]</td>\n";
    }
    echo "  </tr>\n";
  }
  echo "</table>\n";
}

echo "<br>";
   if ($num > $rows_per_page) {
       $seiten=floor($num/$rows_per_page);

           if ($seiten == $num/$rows_per_page) {
               $schluss = $seiten;
           }
           if ($seiten < $num/$rows_per_page) {
               $seiten++;
               $schluss = $seiten;
           }
    }

if (isset($seiten)) {
    for ($a =0; $a<$seiten; $a++) {
        $mail = @mysql_result($daten,$a, "mail");
        if ($a == 0) {
            echo "<A HREF=\"update_order_all.php?page=$a\">Seite 1</A>";
        }
        if (($a > 0) And  (($a +1) < $schluss)) {
            $b = $a + 1;
            echo "<A HREF=\"update_order_all.php?page=$a\">$b</A>";
        }
        if (($a +1 ) == $schluss) {
            echo "<A HREF=\"update_order_all.php?page=$a\">letzte Seite</A>";
        }
        if (($a + 1) < ($seiten)) {
            echo "&nbsp;|&nbsp;";
        }
    }

Posted: Wed Jan 25, 2006 10:52 am
by raghavan20
have you got the link to the working page?

Posted: Wed Jan 25, 2006 7:29 pm
by joecrack
no i am sorry its a company intern network. and i dont have the database and everything on a public server=(
so is there nothing you can see why this problem appears? or anything that you think it COULD be the prob?

Posted: Wed Jan 25, 2006 7:35 pm
by raghavan20
is it possible for you to post the snapshot of output captured in a browser? Do you see the same problem in both browsers, IE & Firefox?

EDIT: why do you have a '\n' for a td?

Code: Select all

for ($i = 3; $i < mysql_num_fields($daten); $i++){ 
      echo "    <td>$row[$i]</td>\n"; 
    }

Posted: Wed Jan 25, 2006 8:08 pm
by joecrack
yeah the /n are senseless. i forgot to delete them when i copied the output code from anpother script last time.
so in the code i posted here, there are a not as many variables in the SELECT as on the screenshot - but thats just because i didnt want the code to be that long. now i shrunk the firefox screen a little so you can see better what the problem is. now i put in limit 15 and its not even working anymore. the output starts with 15 datasets, then opens the next table with 14 datasets and so on ... until you only have the table headers left. and on the bottom finally i have the links that should send you to the next 15 datasets.
http://www.comtrexx.de/untitled1.jpg
http://www.comtrexx.de/untitled2.jpg
i think it could be something with the for-clause !?!!

Posted: Wed Jan 25, 2006 9:29 pm
by raghavan20
i think there could be something wrong with the if (isset ($_GET['page'])) because it returns FALSE!?!?!
Ofcourse, it would be, because I do not see you passing any URL parameter in the URL from the snapshot.

Code: Select all

for ($i =0; $i<$rows_per_page; $i++) { 
        $mail = @mysql_result($daten,$i, "mail"); 

        if (isset ($_GET['page'])) { 
            $page = $_GET['page']; 
            $start=$page * $rows_per_page; 
        } 
        else { 
        $start = 0; 
        $page = 0; 
        } 

        $sqlab = "SELECT sam_date_val.Incdate,sam_date_val.Customernr,sam_date_val.Projnr,sam_bestellung.Area,sam_bestellung.Groupp FROM sam_date_val,sam_bestellung WHERE sam_bestellung.projnr=sam_date_val.projnr AND sam_bestellung.customernr=sam_date_val.customernr ORDER BY customernr LIMIT $start,$Zeilen_pro_Seite"; 

        $daten = mysql_query($sqlab) OR die(mysql_error()); 

        $mail = @mysql_result($daten,$i, "mail"); 
echo "<table border=\"4\", align=\"center\", cellpadding=\"3\", rules=\"all\"><caption style=\"caption-side:top;\"><strong>Present Orders List</strong></caption>\n"; 
  echo "  <tr>\n"; 
echo" 
<th nowrap>Incoming Date</th> 
<th nowrap colspan=\"2\">Project No</th> 
<th nowrap>Area</th> 
<th nowrap>Group</th> 
"; 
echo "  </tr>\n"; 

  while ($row = mysql_fetch_row($daten)){ 
    echo "  <tr>\n"; 
    echo" 
    <td>$row[0]</td> 
    <td colspan=\"2\">$row[1]$row[2]</td>"; 

    for ($i = 3; $i < mysql_num_fields($daten); $i++){ 
      echo "    <td>$row[$i]</td>\n"; 
    } 
    echo "  </tr>\n"; 
  } 
  echo "</table>\n"; 
}
I want some clarification from above code... you have a while loop nested inside a for loop...do you really mean to do it.

where this variable used in query, $Zeilen_pro_Seite, is initialized?

If you carefully examine, you can see $start in LIMIT is moving forwarding by one and at the same time $Zeilen_pro_Seite is getting decremented by one and finally you have a table with no result.

You are getting the $mail value but I do not see you printing it out anywhere. :?

You are using two for loops with $i as counter, please change one of them to some other variable.

EDIT: Please align your code properly and post in the original post again. It is too hard to identify blocks of code....

Posted: Wed Jan 25, 2006 9:50 pm
by joecrack
ok sorry ... i wanted to make it more clear, with changeing zeilen_pro_seite (its german) to rows_per_page.
i changed the code and nor it looks like this. only one $i loop. but i really dont know what the $mail is for.
its not completely my code - so i left that one in there :roll:

Code: Select all

$sqlab = "SELECT sam_date_val.Incdate,sam_bestellung.Area,sam_bestellung.Groupp,sam_date_val.Customernr,sam_date_val.Projnr,sam_bestellung.Designer,sam_bestellung.Yard,sam_bestellung.Hull,sam_bestellung.EqDes,sam_date_val.TOValue,sam_date_val.PlannedMonth,sam_date_val.Actdeldate FROM sam_date_val,sam_bestellung WHERE sam_bestellung.projnr=sam_date_val.projnr AND sam_bestellung.customernr=sam_date_val.customernr AND sam_date_val.incdate BETWEEN DATE '$year-01-01' AND DATE '$year-12-31' ORDER BY incdate";
  mysql_select_db('safe');
   $daten = mysql_query($sqlab) OR die(mysql_error());
   $num = mysql_num_rows($daten);

   if ($num == 0) {
       $istanzahl = "keine";
   }
    if ($istanzahl == "keine") {
         echo "<font size=\"2\" face=\"Verdana\">No Datasets found.</font>";
    }

    $Zeilen_pro_Seite = 20;
    $maximal_ergebnisse = 1000;

if ($num > $maximal_ergebnisse) {
    echo "<br>Es werden maximal nur $maximal_ergebnisse Eintr&auml;ge angezeigt, es wurden aber $num Eintr&auml;ge gefunden.<br><br>";
    $num = $maximal_ergebnisse;
    }
    for ($i =-1; $i<$Zeilen_pro_Seite; $i++) {
        $mail = @mysql_result($daten,$i, "mail");

        if (isset ($_GET['page'])) {
            $page = $_GET['page'];
            $start=$page * $Zeilen_pro_Seite;
        }
        else {
        $start = 0;
        $page = 0;
        }

        $sqlab = "SELECT sam_date_val.Incdate,sam_bestellung.Area,sam_bestellung.Groupp,sam_date_val.Customernr,sam_date_val.Projnr,sam_bestellung.Designer,sam_bestellung.Yard,sam_bestellung.Hull,sam_bestellung.EqDes,sam_date_val.TOValue,sam_date_val.PlannedMonth,sam_date_val.Actdeldate FROM sam_date_val,sam_bestellung WHERE sam_bestellung.projnr=sam_date_val.projnr AND sam_bestellung.customernr=sam_date_val.customernr AND sam_date_val.incdate BETWEEN DATE '$year-01-01' AND DATE '$year-12-31' ORDER BY incdate LIMIT $start,$Zeilen_pro_Seite";

        $daten = mysql_query($sqlab) OR die(mysql_error());
        $mail = @mysql_result($daten,$i, "mail");


$result = mysql_query("SELECT SUM( tovalue ) 'SUM' FROM sam_date_val WHERE sam_date_val.incdate<'$year-01-01' AND sam_date_val.actdeldate='0000-00-00'");
$sum = mysql_fetch_array($result);

echo "
<table border=\"4\", align=\"center\", cellpadding=\"3\", rules=\"all\"><caption style=\"caption-side:top;\"><strong>Present Orders List</strong></caption>\n";
echo "  <tr>";
echo"
<th nowrap>Incoming Date</th>
<th nowrap>Area</th>
<th nowrap>Group</th>
<th nowrap colspan=\"2\">Project No</th>
<th nowrap>Designer</th>
<th nowrap>Customer</th>
<th nowrap>Equipment</th>
<th nowrap>Sales Price</th>
<th nowrap>Delivery Date</th>
<th nowrap>Orders incoming</th>
<th nowrap>Actual Del Date</th>
<th nowrap>Orders in stock</th>";
echo "  </tr>";
echo "  <tr>";
echo"
<td nowrap>Backlog</td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap></td>
<td nowrap>".$sum['SUM']."</td>";
echo "  </tr>";

  while ($row = mysql_fetch_row($daten)){

	if ($row[7]!=''){
		$der['strich']='&nbsp;-&nbsp;';
	}
	elseif ($row[7]==''){
		$der['strich']='';
	}
$tovaluesum=$tovaluesum+$row[9];

if ($row[11]!='0000-00-00'){
	$sum['SUM']=$sum['SUM']+$row[9];
	$backsum=$sum['SUM'];
}
	elseif ($row[11]=='0000-00-00'){
		$backsum='00.00';
	}
    echo "  <tr>";
	echo"
	<td>$row[0]</td>
	<td>$row[1]</td>
	<td>$row[2]</td>
	<td colspan=\"2\">$row[3]$row[4]</td>
	<td>$row[5]</td>
	<td>".$row[6].''.$der['strich'].''.$row[7]."</td>
	<td>$row[8]</td>
	<td>$row[9]</td>
	<td>$row[10]</td>
	<td>$tovaluesum</td>
	<td>$row[11]</td>
	<td>$backsum</td>";
    echo "  </tr>";
  }
  echo "</table>";
}

Posted: Wed Jan 25, 2006 10:04 pm
by raghavan20
This code looks alright...i do not see a problem in it...
few things

This will not work if you do not put those array values in curly braces...

Code: Select all

<td>$row[0]</td> 
    <td>$row[1]</td> 
    <td>$row[2]</td>
Is there a specific reason to use -1

Code: Select all

for ($i =-1; $i<$Zeilen_pro_Seite; $i++) {
Your code will create new table for every $Zeilen_pro_Seite, because it is written to work like that; for every for loop you are running an entire while loop with <table></table>.

Run your new code and post images.

Posted: Wed Jan 25, 2006 11:20 pm
by joecrack
there is a reason why i put in -1.
But you know what the table is supposed to do.
Put the table with the same number of datasets on the NEXT PAGE.
And now that i changed the html code for the table it is not working at all.
With the first code that i posted it worked for a dataset limit up to 22.
And after changing it did this error that is shown on the pictures.
Also with other outputs it works fine with a maxrows of 22!?!?

Posted: Thu Feb 09, 2006 3:15 am
by joecrack
could it be, that the problem is because of these results, that i dont use.
i have to say that its not my script :roll:
but i think this limits the output in someway !?!!

Code: Select all

$mail = @mysql_result($daten,$i, "mail");

Posted: Thu Feb 09, 2006 4:41 am
by raghavan20
joecrack wrote:could it be, that the problem is because of these results, that i dont use.
i have to say that its not my script :roll:
but i think this limits the output in someway !?!!

Code: Select all

$mail = @mysql_result($daten,$i, "mail");
take out the @ symbol before mysql_result to look out for errors...what I would advise you is, this page is not too long to be developed, you can do it within two hours,,, you create a new file and start coding it and take elements from the older file if needed,,,you should be able to do it.