简体   繁体   中英

show large records from more than one table mysql

Hi to all my friends out there,im facing a problem when i need to show all the purchase list from more than one table.let said 5 table named as "tablet","syrup","capsul","injection","flask",each purchase from user have to be shown in one page,lets said got 20 record from each table so total will be 100 row to be shown.the question is how to show only 10 row from each table but providing next and prev button,while each of next button wont influence the other table.here's the code.The problems is i got more than 1 mill users and there's a case when almost all of them view their purchase at the same time and my server gone.Thanks for all your help.heres the provided source.

$rs = mysql_query("SELECT * FROM tablet WHERE zomname ='".$_SESSION['username']."';",$conn) or die("Couldn't fetch records from stud");
$rs2 = mysql_query("SELECT * FROM syrup WHERE zomname ='".$_SESSION['username']."';",$conn) or die("Couldn't fetch records from stud");
$rs3 = mysql_query("SELECT * FROM capsul WHERE zomname ='".$_SESSION['username']."' LIMIT 10;",$conn) or die("Couldn't fetch records from stud");
$rs4 = mysql_query("SELECT * FROM injection WHERE zomname ='".$_SESSION['username']."';",$conn) or die("Couldn't fetch records from stud");
$rs5 = mysql_query("SELECT * FROM flask WHERE zomname ='".$_SESSION['username']."';",$conn) or die("Couldn't fetch records from stud");


$count=mysql_num_rows($rs);
$count2=mysql_num_rows($rs2);
$count3=mysql_num_rows($rs3);
$count4=mysql_num_rows($rs4);
$count5=mysql_num_rows($rs5);


if ($count>0 || $count2>0 || $count3>0 || $count4>0 || $count5>0)
{
            echo "<CENTER>";
            echo "<BR><B><U>Purchase</U></B><BR><br/>";
            echo "<TABLE align='center' border='1' cellspacing='0' cellpadding='5'>";
            echo "<TR><TH>Nama</TH><TH colspan='4'>batch</TH><TH>Hprice</TH><TH>Discount</TH><TH>Paid</TH><TH>Product</TH><TH>Branch</TH><TH>Regional</TH><TH>Time</TH></TR>";
            //print Tablet data
            $i=0;
            while($i<$count)
            {
                $name=mysql_result($rs, $i, "zomname");
                $product=mysql_result($rs, $i, "tproduct");
                $bnum1=mysql_result($rs, $i, "batch1");
                $bnum2=mysql_result($rs, $i, "batch2");
                $bnum3=mysql_result($rs, $i, "batch3");
                $bnum4=mysql_result($rs, $i, "batch4");
                $bprice=mysql_result($rs, $i, "price");
                $bprice=number_format($bprice, 0, ',', '.');
                $disc=mysql_result($rs, $i, "Tdiscount");
                $disc = $disc." persen";
                $paid=mysql_result($rs, $i, "Tpaid");
                $paid=number_format($paid, 0, ',', '.');
                $country=mysql_result($rs, $i, "Tbr");
                $Regin=mysql_result($rs, $i, "Treg");
                $date=mysql_result($rs, $i, "zomdate");
                $month=mysql_result($rs, $i, "zomonth");
                $time=mysql_result($rs, $i, "zomtime");
                $actualtime =$date."-".$month.",".$time;
                echo "<TR><TD>$name</TD><TD>$bnum1</TD><TD>$bnum2</TD><TD>$bnum3</TD><TD>$bnum4</TD><TD>$bprice</TD><TD>$disc</TD><TD>$paid</TD><TD>$product</TD><TD>$country</TD><TD>$table</TD><TD>$actualtime</TD></TR>";
                $i++;
            }
            echo "</TABLE></CENTER>";
            echo "<br/>";

//print Syrup data and so on....all of the 5 product type have to be in one page.
//but i can limit to show each 10 item from each product type by providing next n previous button for each product

Do you think pulling your query from the database in blocks of 10 at a time will reduce your net database load? Assuming you have a large number of users executing a large number of small requests, your net load will increase. Not to mention the robustness issues of being sure you have displayed all the data while live transactions may be occuring during the paging operations.

mysql_* is depricated, look at mysqli

As Pixel Maker's comment says - use a table to track the types, hard coding the types into your php is a recipe for future pain.

My recommendations:

1) Give the user plenty of filter options - eg let them specify a purchase date range and purchase type, plus any other useful filters you can think of. This makes the returned data more managable for you to display and the user to find what they are looking for.

2) Grab everything the user requests in one query. Ajax the pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM