Alphabetical Search in PHP

4,965 views
4,781 views

Published on

Using this article one can get easily understand alphabetical search in php.

Published in: Education, Technology
1 Comment
0 Likes
Statistics
Notes
  • PHP + MySQL - transactions dont rollback

    You need to use a transactional database engine. eg INNODB

    You are currently using MyISAM which does not support transactions.

    This means you cannot start or rollback transactions without changing your DB engine.

    then apply rollback and commit

    mysql_query('LOCK TABLES granuls_tbl WRITE;');

    mysql_query('SET AUTOCOMMIT=0;');

    mysql_query('BEGIN;');

    mysql_query('START TRANSACTION;');



    // Insert some values
    $sql='insert into table (zone_name) values ('xxx')';
    $objQuery1=mysql_query($sql);
    $s=mysql_affected_rows();
    $sql='insert into table (zone_names) values ('xxx')';
    $objQuery2=mysql_query($sql);
    $s2=mysql_affected_rows();

    if ($s > 0 and $s2 > 0)

    {

    $result1= mysql_query($log);

    mysql_query('COMMIT;');



    echo '';

    } else {

    mysql_query('ROLLBACK;');

    echo '';

    };
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
4,965
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
75
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Alphabetical Search in PHP

  1. 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. 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. 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. 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

×