Web technology

web developers learning site

Simple paging in a table using php

<html>
<head>
<title> Paginate </title>
</head>
<body>
<form method=’get’>
<?PHP

// database connection
$connection= mysql_connect(‘localhost’,’root’,”);
if(!$connection){
die(‘Connection error’.mysql_error());
}

//check if the starting row variable was passed in the URL or not
if (!isset($_GET[‘startrow’]) or !is_numeric($_GET[‘startrow’])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET[‘startrow’];
}

//this part goes after the checking of the $_GET var
if($connection)
mysql_select_db(‘test_cbl’,$connection)or die(mysql_error());
$fetch = mysql_query(“SELECT * FROM app_npsnps LIMIT $startrow, 10”)or
die(mysql_error());
$num=Mysql_num_rows($fetch);
if($num>0)
{
echo “<table border=2>”;
echo “<tr><td>ID</td><td>Drug</td><td>quantity</td></tr>”;
for($i=0;$i<$num;$i++)
{
$row=mysql_fetch_row($fetch);
echo “<tr>”;
echo”<td>$row[0]</td>”;
echo”<td>$row[1]</td>”;
echo”<td>$row[2]</td>”;
echo”</tr>”;
}//for
echo”</table>”;
}
//now this is the link..
echo ‘<a href=”‘.$_SERVER[‘PHP_SELF’].’?startrow=’.($startrow+10).'”> Next </a>’;

$prev = $startrow – 10;

//only print a “Previous” link if a “Next” was clicked
if ($prev >= 0)
echo ‘<a href=”‘.$_SERVER[‘PHP_SELF’].’?startrow=’.$prev.'”> Previous </a>’;
?>
</form>
</body>
</html>

Linq join query for Asp.net

Here Suppliers and Customers are two tables. Common key company name. Now the linq join query...

1. var q = 
     from s in db.Suppliers
     join c in db.Customers on s.City equals c.City
     select new {
        Supplier = s.CompanyName,
        Customer = c.CompanyName,
        City = c.City
     };

2. var q = 
     from s in db.Suppliers 
     join c in db.Customers on s.City equals c.City into scusts 
     join e in db.Employees on s.City equals e.City into semps 
     select new { s, scusts, semps };

Display a pyramid

1. Write a program to display a pyramid as follow structure..

      *
*    *
*    *   *
*   *
*

int main()
{
int i,j,k,lmt=3;
for(i=1;i<=3;i++)
{
for(k=lmt-i;k>=1;k–)
printf(” “);
for(j=1;j<=i;j++)
printf(” *”);
printf(“\n”);
}

for(i=3-1;i>=1;i–)
{
for(k=lmt-i;k>=1;k–)
printf(” “);
for(j=1;j<=i;j++)
printf(” *”);
printf(“\n”);
}

return 0;
}

Typecasting of object in java programming

class A{
int a = 5;
void test()
{
System.out.print(“A”);
}
}
class J extends A{
int a = 10;
void test(){
System.out.println(“J”);
}
}

public class M extends J  {

int a = 15;
void test()
{
System.out.println(“M”);
}
public static void main(String args[])
{
J obj = new M();
M k = (M)obj;
A a = (A)k;

System.out.println(obj.a +”  “+k.a + ”  “+a.a);
k.test();
a.test();
}
}

 

Output ::

10  15  5
M
M

 

Basic concepts of oop

Basic concepts of oops are :

  1. class
  2. object
  3. Inheritance
  4. polymorphism
  5. abstraction
  6. encapsulation

Post Navigation