0

hi i created this page for displaying my products that it works with select query from data base but after all try i could show the 3 of them in pages but all i want is displaying 6 of them in different tables after each other

please help me with this problem ???

<?php include "db.php";
  
  // row for quantities
$qtyRow = '<tr>';
 
// row for prices
$priceRow = '<tr>';
  
$nn=3;

$s=mysql_query("select * from test1");

$c=mysql_num_rows($s);

if($c%$nn==0)
{
$cc=$c/$nn;	
}
else
{
$cc=$c/$nn+1;	
}
$ss=@$_REQUEST['ss'];

if($ss=="")
{ $sql=mysql_query("select * from test1 order by id desc limit 3");
  while($r=mysql_fetch_array($sql))
{

	$id=$r['id'];  $name=$r['name'];
 
    $qtyRow .= "<td>$id</td>";
 
    $priceRow .= "<td>$name</td>";
 
}
// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';
 
// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
 
echo "</table>";

?>
<?php
}
else
{
$sql=mysql_query("select * from test1 order by id desc limit $ss,3 ");
while($r=mysql_fetch_array($sql))
{

	$id=$r['id'];  $name=$r['name'];
 
    $qtyRow .= "<td>$id</td>";
 
    $priceRow .= "<td>$name</td>";
 

}
// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';
 
// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
 
echo "</table>"; ?>

  <?php  } ?>
</p>
<?php
$j=0;
	echo"page : ";
for($i=1;$i<=$cc;$i++)
{
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>

you suppose that this is my table that showed 3 of them in one table :

10 9 8
k a s

i wanna change it to this kind of form :

10 9 8
k a s

7 6 5
q z w


and then i m gonna change my pages with this form

page : 1|2|3|4|

4
Contributors
26
Replies
27
Views
5 Years
Discussion Span
Last Post by turt2live
Featured Replies
  • If you are looking to do something like [URL="http://turt2live.com/dani_test/items.php?ss=0"]this[/URL], use the following code. [CODE]<?php include "db.php"; //Rows $qtyRow = '<tr>'; $priceRow = '<tr>'; $nn=3; //Number of items $s=mysql_query("SELECT * FROM `test1`"); $c=mysql_num_rows($s); if($c%$nn==0){ $cc=$c/$nn; }else{ $cc=$c/$nn+1; } //$cc : Number of pages $ss=@$_REQUEST['ss']; //Start position (eg: 3) $other_tables = ""; … Read More

  • The change on the sample page I showed you is reflected to match this code: (Which I think is what you want) [CODE]<?php include "db.php"; //Rows $qtyRow = '<tr>'; $priceRow = '<tr>'; $nn=3; //Number of items $s=mysql_query("SELECT * FROM `test1`"); $c=mysql_num_rows($s); if($c%$nn==0){ $cc=$c/$nn; }else{ $cc=$c/$nn+1; } //$cc : Number of … Read More

  • All right, I think I got it. Test it out [URL="http://turt2live.com/dani_test/items.php?ss=0"]here[/URL], the code is below: [CODE]<?php include "db.php"; //Rows $qtyRow = '<tr>'; $priceRow = '<tr>'; $nn=6; //Number of items, we split this later $s=mysql_query("SELECT * FROM `test1`"); $c=mysql_num_rows($s); if($c%$nn==0){ $cc=$c/$nn; }else{ $cc=$c/$nn+1; } //$cc : Number of pages $ss=@$_REQUEST['ss']; //Start … Read More

  • There. Sorry about that, I missed a check to see if it hit the max value or not. [CODE]<?php include "db.php"; //Rows $qtyRow = '<tr>'; $priceRow = '<tr>'; $nn=6; //Number of items, we split this later $s=mysql_query("SELECT * FROM `test1`"); $c=mysql_num_rows($s); if($c%$nn==0){ $cc=$c/$nn; }else{ $cc=$c/$nn+1; } //$cc : Number of … Read More

0

Do your results need to be returned as columns/rows like that? It is much easier to return the details as rows and columns instead (also, more legible in my experience.)

[U][B]id | data[/U][/B]
10 | k
 9 | a
 8 | s
0

Thanks but as i said i need mentioned form for displaying my products

i want 2 table that they are after each other i knew the easiest ways but this is my
project i couldn't change the rules

i need urgent help !!

0

Are you just copy and pasting random bits of code together? You have bad syntax all over the place, so first things first you need to clean up your code (closing PHP and then the following line re-opening it...)

If you are trying to use multiple pages, Google "php pagination", that'll help you display the correct number of results per page.

0

where can i find it my friend ?

and where is the problem in my code ???
it works correctly but i think i cant explain what i need ?

0

Try this...

<?php

$ss = intval($_GET['ss']);  // Intval converts ss into a number and returns 0 if ss is 0 or NOT a number.

$sql=mysql_query("select * from test1 order by id desc limit $ss,3 ");

$sets = 2;
$currentSet = 1;
$count = 0;
$rowCount = 0;
do {
	$idRow = '<tr><th>ID:</th>'; 
	$nameRow = '<tr><th>Name:</th>';
	while($r=mysql_fetch_array($sql) && $rowCount++ < 3)
	{
	 
		$id=$r['id'];  $name=$r['name'];
	 
		$idRow .= "<td>$id</td>";
	 
		$nameRow .= "<td>$name</td>";
	 
		$count++;
	 
	}
	
	$idRow = '</tr>'; 
	$nameRow = '</tr>';
	echo '<table class="ProductTable">'.$idRow.$nameRow.'</table>';
	$rowCount = 0;
	
} while (mysql_num_rows($sql) > $count && ++$currentSet <= $sets)

?>

Edited by madCoder: Fixed a bug I spotted related to rowCount.

0

I cleaned up your code for you, but I can't help you any further if you don't describe with comments what $ss, $nn, and such actually mean.

<?php 
include "db.php";
  
//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
  
$nn=3;

$s=mysql_query("select * from test1");

$c=mysql_num_rows($s);

if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}

$ss=@$_REQUEST['ss'];

if($ss=="" || $ss==null){ 
	$sql=mysql_query("select * from test1 order by id desc limit 3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  $name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
	// end of the rows
	$qtyRow .= '</tr>';
	$priceRow .= '</tr>';
}else{
	$sql=mysql_query("select * from test1 order by id desc limit $ss,3 ");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  $name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
	// end of the rows
	$qtyRow .= '</tr>';
	$priceRow .= '</tr>';
} 

// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
echo "</table>";
echo "</p>";  //No idea why this is here
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
0

i used $nn as what number of things i want to show for example 3 of them in each page and then i used % for both of the conditions if $c%%nn==0 it means the result equally shows 0 pages but in the else situation we have 1 or more objects to show in other pages such as 2 or 3 or... so is it clear ???

excuse me sir but once again i m gonna repeat the question :

this is my result in each page :

10 9 8
k a s

i wanna add another table after this that it remain the information until it is going to next page :

10 9 8
k a s

7 6 5
q z w

the second table continuing info's in each page .

Is there still any things wrong here ?

1

If you are looking to do something like this, use the following code.

<?php 
include "db.php";

//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
  
$nn=3; //Number of items

$s=mysql_query("SELECT * FROM `test1`");

$c=mysql_num_rows($s);

if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}

//$cc : Number of pages

$ss=@$_REQUEST['ss']; //Start position (eg: 3)
$other_tables = "";

if($ss=="" || $ss==null){  //First page
	$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT 3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  
		$name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
}else{ //Other pages
	$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  
		$name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
	
	//Get other results
	$ss = $ss - 3;
	while($ss >= 0){
		$other_tables .= "<br><table border='1' align='center'>";
		$other_qty = "<tr>";
		$other_price = "<tr>";
		$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,3");
		while($r=mysql_fetch_array($sql)){
			$id=$r['id'];  
			$name=$r['name'];
			$other_qty .= "<td>$id</td>";
			$other_price .= "<td>$name</td>";
		}
		$other_qty .= "</tr>";
		$other_price .= "</tr>";
		$other_tables .= $other_qty . $other_price;
		$other_tables .= "</table>";
		$ss = $ss - 3;
	}
} 
// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';
// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
echo "</table>";
echo $other_tables;
echo "</p>";  //No idea why this is here
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
0

Many Thanks

i m sorry but one question again ?

your written code is ok but if i wanna show two table like page 2 in your code and in the every page i want to use this method what should i do ?


7 6 5
w q g

10 9 8
k a s


Page 2

this is my question

i want to repeat this method in each page .

1

The change on the sample page I showed you is reflected to match this code:

(Which I think is what you want)

<?php 
include "db.php";

//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
  
$nn=3; //Number of items

$s=mysql_query("SELECT * FROM `test1`");

$c=mysql_num_rows($s);

if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}

//$cc : Number of pages

$ss=@$_REQUEST['ss']; //Start position (eg: 3)
$other_tables = "";

if($ss=="" || $ss==null || $ss==0){  //First page
	$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT 3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  
		$name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
}else{ //Other pages
	$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  
		$name=$r['name'];
		$qtyRow .= "<td>$id</td>";
		$priceRow .= "<td>$name</td>";
	}
	
	//Get other results
	$ss = $ss - 3;
	$other_tables .= "<br><table border='1' align='center'>";
	$other_qty = "<tr>";
	$other_price = "<tr>";
	$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,3");
	while($r=mysql_fetch_array($sql)){
		$id=$r['id'];  
		$name=$r['name'];
		$other_qty .= "<td>$id</td>";
		$other_price .= "<td>$name</td>";
	}
	$other_qty .= "</tr>";
	$other_price .= "</tr>";
	$other_tables .= $other_qty . $other_price;
	$other_tables .= "</table>";
} 
// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';
// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
echo "</table>";
echo $other_tables;
echo "</p>";  //No idea why this is here
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
0

did you test it ???


it doesn't work like i said !

it is your same code that u sent and it was great but as i said i wanna follow this method in every page :

7 6 5
w q g

10 9 8
k a s


your code has a little bit different with which i said and that was in your code when i change the pages the number of tables going to increase but i wanna to be same tables in each page

each page = 2 tables just it my friend please accept my apologize

0

it doesnt work on first page

please just fix the first page for me

0

page 3 in your code is my exact idea .

2 tables that they are after each other without repeat any data

could you review it again ?

0

I just want to confirm:

As an example:

page 1:

3 2 1
c b a

6 5 4
f e d

Page 2:

6 5 4
f e d

9 8 7
i h g

page 3:

9 8 7
i h g

12 11 10
l k j

.. And so on

Correct?

0

Yes wonderful

Page 1 :


10 9 8
k a s


7 6 5
w q g


Page 2 :


4 3 2
r e d

1
s


and so on ...

thanks ( without repeat )

1

All right, I think I got it.

Test it out here, the code is below:

<?php 
include "db.php";

//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
  
$nn=6; //Number of items, we split this later

$s=mysql_query("SELECT * FROM `test1`");

$c=mysql_num_rows($s);

if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}

//$cc : Number of pages

$ss=@$_REQUEST['ss']; //Start position (eg: 6)
$other_tables = "";

if($ss=="" || $ss==null){
	$ss = 0; //Set to zero because it is incremented later
}

//Pages
echo "<table border=\"1\" align=\"center\">";
$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,$nn");
$inc = 0;
while($r=mysql_fetch_array($sql)){
	$id=$r['id'];  
	$name=$r['name'];
	if($inc == 0){
		$qtyRow .= "<tr>";
		$priceRow .= "<tr>";
	}
	$qtyRow .= "<td>$id</td>";
	$priceRow .= "<td>$name</td>";
	++$inc;
	if($inc == 3 || $inc == 6){
		//Display Table
		echo $qtyRow."</tr>";
		echo $priceRow."</tr>";
		echo "</table>";
		
		//To remove extra table
		if(mysql_num_rows($sql) < 6){
			$inc = 7;
		}
		
		//Reset
		if($inc == 3){
			echo "<br><table border='1' align='center'>";
			$qtyRow = "<tr>";
			$priceRow = "<tr>";
		}
	}
}
echo "</table>";
echo "</p>";  //No idea why this is here
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
0

Thanks it works correct

but where is number 1 data s ?


4 3 2
r e d

1
S

missed !!!

0

I don't see where you are seeing that error, when I run the script I see 2 possible pages I can go to. When I first go there I am presented with page 1, which has IDs 9, 8, 7, and 6, 5, 4, then I click page 2 and see the remaining 3 IDs, 3, 2, and 1.

0

when I run the script I see 2 possible pages I can go to. When I first go there I am presented with page 1, which has IDs 9, 8, 7, and 6, 5, 4, then I click page 2 and see the remaining 3 IDs, 3, 2, and 1.

so where is 10 ?

if you dont saw the 10 because of the code that i cant see the 1 !

0

if you add some data like number 11 or 12 or .... you will be see the page still in 2 pages that it is gonna miss numbers from the beginning of them ...

0

I increased the data to number 13 and now it is ok

but still I don't have number 1 !

probably missed

1

There. Sorry about that, I missed a check to see if it hit the max value or not.

<?php 
include "db.php";

//Rows
$qtyRow = '<tr>';
$priceRow = '<tr>';
  
$nn=6; //Number of items, we split this later

$s=mysql_query("SELECT * FROM `test1`");

$c=mysql_num_rows($s);

if($c%$nn==0){
	$cc=$c/$nn;	
}else{
	$cc=$c/$nn+1;	
}

//$cc : Number of pages

$ss=@$_REQUEST['ss']; //Start position (eg: 6)
$other_tables = "";

if($ss=="" || $ss==null){
	$ss = 0; //Set to zero because it is incremented later
}

//Pages
echo "<table border=\"1\" align=\"center\">";
$sql=mysql_query("SELECT * FROM `test1` ORDER BY `id` DESC LIMIT $ss,$nn");
$inc = 0;
while($r=mysql_fetch_array($sql)){
	$id=$r['id'];  
	$name=$r['name'];
	if($inc == 0){
		$qtyRow .= "<tr>";
		$priceRow .= "<tr>";
	}
	$qtyRow .= "<td>$id</td>";
	$priceRow .= "<td>$name</td>";
	++$inc;
	if($inc == 3 || $inc == 6 || $inc == mysql_num_rows($sql)){
		//Display Table
		echo $qtyRow."</tr>";
		echo $priceRow."</tr>";
		echo "</table>";
		
		//To remove extra table
		if(mysql_num_rows($sql) <= 3){
			$inc = 7;
		}
		
		//Reset
		if($inc == 3){
			echo "<br><table border='1' align='center'>";
			$qtyRow = "<tr>";
			$priceRow = "<tr>";
		}
	}
}
echo "</table>";
echo "</p>";  //No idea why this is here
$j=0;
echo"page : ";
for($i=1;$i<=$cc;$i++){
	echo"<a href=\"select.php?ss=$j\">$i</a>";
	echo"|";
	$j=$j+$nn; 
}
?>
0

MANY MANY THANKS

ACCEPT MY APOLOGIZE FOR WASTING YOUR TIME MY FRIEND ...

my pleasure to meet you

0

You are welcome, enjoy your script!!


(Please note: If you consider this thread solved, please mark it as so! It helps both me and you out on <DANIWEB>!)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.