SlideShare ist ein Scribd-Unternehmen logo
1 von 4
Downloaden Sie, um offline zu lesen
PHP Tutorials By Vineet Kumar Saini

Alphabetical Search in PHP
First of all we create a table in database. Suppose we created ‘student’ table in ‘test’ database.
Like as following image

<html>
<body>
<p><center>
<h3>Alphabetical Search in PHP</h3>
<form action="index.php" method="post" name="search" onclick="submit">
<a href="index.php?letter=A">A</a> |
<a href="index.php?letter=B">B</a> |
<a href="index.php?letter=C">C</a> |
<a href="index.php?letter=D">D</a> |
<a href="index.php?letter=E">E</a> |
<a href="index.php?letter=F">F</a> |
<a href="index.php?letter=G">G</a> |
<a href="index.php?letter=H">H</a> |
<a href="index.php?letter=I">I</a> |
<a href="index.php?letter=J">J</a> |
<a href="index.php?letter=K">K</a> |
<a href="index.php?letter=L">L</a> |
<a href="index.php?letter=M">M</a> |
<a href="index.php?letter=N">N</a> |
<a href="index.php?letter=O">O</a> |
<a href="index.php?letter=P">P</a> |
<a href="index.php?letter=Q">Q</a> |
<a href="index.php?letter=R">R</a> |
<a href="index.php?letter=S">S</a> |
<a href="index.php?letter=T">T</a> |
<a href="index.php?letter=U">U</a> |
<a href="index.php?letter=V">V</a> |
<a href="index.php?letter=W">W</a> |
<a href="index.php?letter=X">X</a> |
<a href="index.php?letter=Y">Y</a> |
<a href="index.php?letter=Z">Z</a> |
<a href="index.php?letter=">View All</a>
</form>
<br />

http://vineetsaini.wordpress.com
PHP Tutorials By Vineet Kumar Saini
</center></p>
</body>
</html>
<?php
if(isset($_GET['letter']))
{
$con=mysql_connect('localhost','root','');
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('test',$con);
$char=$_GET['letter'];
if($char)
{
$query = "SELECT * FROM student WHERE name LIKE '$char%' ";
$result = mysql_query($query);
$count=mysql_num_rows($result);
if($count >= 1)
{
?>
<center>
<table cellpadding="1" cellspacing="0" border="1" width="35%" >
<tr>
<th>Name</th>
<th>Class</th>
<th>Email</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><?php echo $row['name']; ?></td>
<td align="center"><?php echo $row['class']; ?></td>
<td align="center"><?php echo $row['email']; ?></td>
</tr>
<?php
}
?>
</table>
<center>
<?php
}
else
{
echo 'Records Not Found';
}
}
else
{
$query = "SELECT * FROM student";
$result = mysql_query($query);
?>

http://vineetsaini.wordpress.com
PHP Tutorials By Vineet Kumar Saini
<center>
<table cellpadding="1" cellspacing="0" border="1" width="35%" >
<tr>
<th>Name</th>
<th>Class</th>
<th>Email</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><?php echo $row['name']; ?></td>
<td align="center"><?php echo $row['class']; ?></td>
<td align="center"><?php echo $row['email']; ?></td>
</tr>
<?php
}
?>
</table>
</center>
<?php
}
}
?>

Then we run the code and click on ‘A’ then display result of A. Like as following image

If we click on ‘V’ then display result of ‘V’. Like as following image

http://vineetsaini.wordpress.com
PHP Tutorials By Vineet Kumar Saini

If we click on ‘View All’ then display full data from table.Like as following image

http://vineetsaini.wordpress.com

Weitere ähnliche Inhalte

Mehr von Vineet Kumar Saini (20)

Abstract Class and Interface in PHP
Abstract Class and Interface in PHPAbstract Class and Interface in PHP
Abstract Class and Interface in PHP
 
Introduction to Html
Introduction to HtmlIntroduction to Html
Introduction to Html
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Stripe in php
Stripe in phpStripe in php
Stripe in php
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Install Drupal on Wamp Server
Install Drupal on Wamp ServerInstall Drupal on Wamp Server
Install Drupal on Wamp Server
 
Joomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDFJoomla 2.5 Tutorial For Beginner PDF
Joomla 2.5 Tutorial For Beginner PDF
 
Functions in PHP
Functions in PHPFunctions in PHP
Functions in PHP
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Database connectivity in PHP
Database connectivity in PHPDatabase connectivity in PHP
Database connectivity in PHP
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Browser information in PHP
Browser information in PHPBrowser information in PHP
Browser information in PHP
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 

Kürzlich hochgeladen

Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptxmary850239
 

Kürzlich hochgeladen (20)

Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptx
 

Alphabetical Search in PHP

  • 1. PHP Tutorials By Vineet Kumar Saini Alphabetical Search in PHP First of all we create a table in database. Suppose we created ‘student’ table in ‘test’ database. Like as following image <html> <body> <p><center> <h3>Alphabetical Search in PHP</h3> <form action="index.php" method="post" name="search" onclick="submit"> <a href="index.php?letter=A">A</a> | <a href="index.php?letter=B">B</a> | <a href="index.php?letter=C">C</a> | <a href="index.php?letter=D">D</a> | <a href="index.php?letter=E">E</a> | <a href="index.php?letter=F">F</a> | <a href="index.php?letter=G">G</a> | <a href="index.php?letter=H">H</a> | <a href="index.php?letter=I">I</a> | <a href="index.php?letter=J">J</a> | <a href="index.php?letter=K">K</a> | <a href="index.php?letter=L">L</a> | <a href="index.php?letter=M">M</a> | <a href="index.php?letter=N">N</a> | <a href="index.php?letter=O">O</a> | <a href="index.php?letter=P">P</a> | <a href="index.php?letter=Q">Q</a> | <a href="index.php?letter=R">R</a> | <a href="index.php?letter=S">S</a> | <a href="index.php?letter=T">T</a> | <a href="index.php?letter=U">U</a> | <a href="index.php?letter=V">V</a> | <a href="index.php?letter=W">W</a> | <a href="index.php?letter=X">X</a> | <a href="index.php?letter=Y">Y</a> | <a href="index.php?letter=Z">Z</a> | <a href="index.php?letter=">View All</a> </form> <br /> http://vineetsaini.wordpress.com
  • 2. PHP Tutorials By Vineet Kumar Saini </center></p> </body> </html> <?php if(isset($_GET['letter'])) { $con=mysql_connect('localhost','root',''); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('test',$con); $char=$_GET['letter']; if($char) { $query = "SELECT * FROM student WHERE name LIKE '$char%' "; $result = mysql_query($query); $count=mysql_num_rows($result); if($count >= 1) { ?> <center> <table cellpadding="1" cellspacing="0" border="1" width="35%" > <tr> <th>Name</th> <th>Class</th> <th>Email</th> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td align="center"><?php echo $row['name']; ?></td> <td align="center"><?php echo $row['class']; ?></td> <td align="center"><?php echo $row['email']; ?></td> </tr> <?php } ?> </table> <center> <?php } else { echo 'Records Not Found'; } } else { $query = "SELECT * FROM student"; $result = mysql_query($query); ?> http://vineetsaini.wordpress.com
  • 3. PHP Tutorials By Vineet Kumar Saini <center> <table cellpadding="1" cellspacing="0" border="1" width="35%" > <tr> <th>Name</th> <th>Class</th> <th>Email</th> </tr> <?php while($row = mysql_fetch_array($result)) { ?> <tr> <td align="center"><?php echo $row['name']; ?></td> <td align="center"><?php echo $row['class']; ?></td> <td align="center"><?php echo $row['email']; ?></td> </tr> <?php } ?> </table> </center> <?php } } ?> Then we run the code and click on ‘A’ then display result of A. Like as following image If we click on ‘V’ then display result of ‘V’. Like as following image http://vineetsaini.wordpress.com
  • 4. PHP Tutorials By Vineet Kumar Saini If we click on ‘View All’ then display full data from table.Like as following image http://vineetsaini.wordpress.com