This is PHP4 Code!

w3schools.com SQL Guide

Simple Get A Result


  $query = @mysql_query("SELECT user_name, password FROM member_profile WHERE email_address = '$user_name_login' AND password = '$password_login'");
  $result = @mysql_fetch_array($query);
  $result_display_username = $result['user_name'];
  $result_username = strtolower($result['user_name']);

Does Record Exist


  $query = @mysql_query("SELECT * FROM my_table WHERE some_field = $some_field AND some_field2 = $some_field2 AND some_field3 = 'yes'");
  if (@mysql_num_rows($query))
  {

Get Each Row Returned


  $query1 = @mysql_query("SELECT * FROM some_table WHERE some_field = $some_value AND approved = 'pending'");
  while ($result1 = @mysql_fetch_array($query1))    //Get each row returned
  {
    $m_title = $result1['member_username'];
    //Do something with it...
  }

Get Number Of Rows Returned


  $count = @mysql_num_rows($query);

Get Specific Columns


  $query_user_details = mysql_query("SELECT first_name, last_name, image_file_name FROM member_profile WHERE member_id = $user_id");

Get each field as a variable named as the field


  foreach ( $result as $key => $value )
  {
    $$key = $value;
  }

Using OR Arguments


$sql = "SELECT * FROM videos WHERE response_id = $vid AND (video_approved ='yes' || approved ='group' || approved ='school') AND public_private = 'public'";

Putting All Results Into An Array


$all_results = array(); 		//Empty array to hold returned rows
while ($row = @mysql_fetch_array($search_query))
{
	$all_results[] = $row;
}

 

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.