Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
 
 


 

PHP SQL Where

                         

PHP SQL Where is used to modify or change the structure of  table definition based on the condition specified in Where Clause. The PHP SQL Where allows you to update the field based on the condition specified in Where Clause.

Understand with Example

The Tutorial illustrate an example from 'PHP SQL Where'. To grasp the example we create a emp_table whose required fields and datatypes are specified.  In the figure below the first figure show before update the table and the second figure show after update the table.

 

 

 

Table: emp_table before update

 

Table: emp_table after update

 

The PHP SQL Where starts with the <?php tag and end with ?>. The $ variable con is used to assigned the value of mysql_connect () function that accept the parameter local host, user and password to authenticate the connection between PHP and MySQL database. The die script executed when there is a connection failure between the PHP and MySQL. Once the connection is built successfully, the update query operation is performed to update the table 'emp_name' and set the new value for 'emp_name' to sandeep based on the 'emp_id = 1' condition specified in Where Clause. The While loop is used to execute the code repeatedly based on Boolean condition. The loop fetches the records from table until the condition evaluate to true.

Source Code of update_where.php 

<?php
  $con = mysql_connect("localhost""root""root");
  if (!$con){
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test", $con);

  $update = "UPDATE emp_table SET emp_name = 'sandeep' WHERE emp_id = 1";

  mysql_query($update, $con);

  echo "Column <b>emp_name</b> updated successfully<br><br>";

  $result = mysql_query("SELECT * FROM emp_table");

  while ($row = mysql_fetch_array($result)) {
      echo "<br>";
      echo $row['emp_id'] "<br>";
      echo $row['emp_name'] "<br>";
      echo $row['emp_designation'] "<br>";
      echo "<br>";
    }

  mysql_close($con);
?>

Download Source Code

Output:

                         

» View all related tutorials
Related Tags: sql mysql c string com sed char compare operator using opera character like cte to ld e il li use

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.