SugarCRM/MySQL

PHP Mysql 기본

onesixx 2012. 11. 7. 21:31
반응형

http://www.siteground.com/tutorials/php-mysql/display_table_data.htm

http://net.tutsplus.com/tutorials/php/how-to-generate-a-complete-excel-spreadsheet-from-mysql/

http://snipplr.com/view/58649/

http://www.daniweb.com/web-development/php/threads/444781/displaying-mysql-results-in-excel

http://www.freewebmasterhelp.com/tutorials/phpmysql/1

=========

http://beans9.tistory.com/87   -    [jQuery/Javascript] 달력 datepicker v2.1

 

=======

Testing For PHP and MySQL

<?php
phpinfo();
?>

Creating The Table In PHP

<?php

//0. information
$user="username";
$password="password";
$database="database";

//1. PHP to connect to the MySQL database server
mysql_connect(localhost,$user,$password);

 

//2. PHP to select the database
@mysql_select_db($database) or die( "Unable to select database");


$query="CREATE TABLE contacts
             (id       int(6)        NOT NULL auto_increment,
             first     varchar(15) NOT NULL,last varchar(15) NOT NULL,
             phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,
             fax varchar(20) NOT NULL,email varchar(30) NOT NULL,
             web varchar(30) NOT NULL,PRIMARY KEY (id),
             UNIQUE id (id),KEY id_2 (id))";

 

//3. 1) Executing Commands – No result
mysql_query($query);          // $result=mysql_query($query);  - result

 

//4. closes the connection to the database server
mysql_close();
?>

 

Displaying Data

<form name="action" id="action" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
    Last Name: <input type="text" name="last_name"><br>
                       <input type="Submit">
</form>

<?php
/*
1. Connect to MySQL.
2. Select the database to use.

3. Build a query string.
4. Perform the query.
5. Retrieve the results and output it to a web page.

6. Repeat Steps 3 to 5 until all desired data have been retrieved.
7. Disconnect from MySQL.
*/

require_once('./stuff/login.php');

$last_name=$_POST['last_name'];
//1. Connect to MySQL.
$db_server = mysql_connect($db_hostname,$db_username,$db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
//2. Select the database to use.
@mysql_select_db($db_database) or die( "Unable to select database");
//3. Build a query string.
$query = "SELECT * FROM contacts where last_name like '%$last_name%' ";
//4. Perform the query.
$result=mysql_query($query);

//Counting Rows
$num=mysql_numrows($result);
//7. Disconnect from MySQL.
mysql_close();

echo "
      <center>==============</center><br>
<b><center>Database Output</center></b><br>
      <center>==============</center><br>
";

//6. Repeat Steps 3 to 5 until all desired data have been retrieved.
//Setting Up The Loop
$i=0;
while ($i < $num) {
//5. Retrieve the results and output it to a web page.
    //CODE
    //$variable=mysql_result($result,$i,"fieldname");
     $department=mysql_result($result,$i,"department");
     $phone_mobile=mysql_result($result,$i,"phone_mobile");

echo "
<b>$department</b><br>
mobile: $phone_mobile<br><hr><br>
";
$i++;
}
?>
<input type="button" value="돌아가기" onClick="history.back();" />

 

반응형

'SugarCRM > MySQL' 카테고리의 다른 글

myisam innodb 변경  (0) 2013.05.22
mysql  (0) 2013.05.22
MySQL:: Backup & Recovery  (0) 2013.05.04
[SQL] 행열변환 방법  (0) 2012.11.08
[퍼옴] mysql 조인(Join)에 대하여  (0) 2012.09.22
각 DB 별 테이블 복사 쿼리 구문 MS-SQL  (0) 2012.08.26