Category: PHP & MySQL

deleting multiple database items with checkbox

deleting multiple database items with checkbox

15 October 2008

checkbox code:
<input name=’checkbox[]‘ type=’checkbox’ id=’checkbox[]‘ value=\””.$row['id'].”\”>
Browser output:
<input name=’checkbox[]‘ type=’checkbox’ id=’checkbox[]‘ value=”392″>
Button at the bottom of form:
<input name=’delete’ type=’submit’ id=’delete’ value=’Delete multiple Selected items’>
CODE:
if($delete){
$delete = $_REQUEST['delete'];
$checkbox = $_REQUEST['checkbox'];
$count = count($_REQUEST['checkbox']);
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = “DELETE FROM $tbl_name WHERE id=’$del_id’”;
$result = mysql_query($sql);
}
// if successful refresh page
if($result){
echo “<meta http-equiv=\”refresh\” content=\”0;URL=checkbox.php\”>”;
}

CakePHP

CakePHP

12 September 2008

CakePHP คือ Framework ที่พัฒนาด้วยภาษา PHP ที่เป็น Free,Open-Source โดยการออกแบบโปรแกรม(design patterns) แบบ MVC (Model-view-controller) และ ORM (Object-relational_mapping) เข้ามาเป็นมาตรฐานหรือข้อตกลงในการพัฒนาโปรแกรม ส่วนเรื่อง MVC และ ORM สำหรับคนที่ยังไม่รู้ความหมายและหลักการทำงาน  สามารถอ่านคำอธิบายในหัวข้อถัดไปได้นะครับ  แต่ตอนนี้เรามาทำความเข้าใจกับ CakePHP framework ตัวนี้กันก่อน
ความหมายของ Framework ก็คือ กรอบของการทำงาน แปลตรงตัวเลยครับ Frame + work แต่ถ้ามองในแง่โปรแกรม ก็จะเป็น ข้อกำหนดหรือขอบเขตในการเขียนโปรแกรมให้เป็นไปในรูปแบบเดียวกัน และสามารถนำไปเขียนเพิ่มเพื่อตอบสนองความต้องการอย่างใดอย่างหนึ่งได้ ดังนั้น CakePHP framework ก็จะมี class และ function ต่างๆ ให้เราได้เรียกใช้  โดยที่เราไม่ต้องไปเสียเวลาเขียนขึ้นมาเอง ซึ่งจะทำให้เกิดความรวดเร็วในการพัฒนา Web Application

ความสามารถใน CakePHP framework
- มีลิขสิทธิ์ที่ยืดหยุ่น
- ทำงานร่วมกับ PHP [...]

VirtueMart fixed number of products in main level category

VirtueMart fixed number of products in main level category

12 September 2008

มีปัญหากับลูกค้ามานานแก้ไม่จบซะที เรื่องการนับจำนวนสินค้าในหมวดหมู่หลักของโปรแกรม VirtueMart component ของ Mambo วันนี้ไปเจอวิธีแก้ไขมาแล้วครับ จากเว็บ http://forum.virtuemart.net/index.php?topic=44319.msg141578
ขั้นตอนแรกไปที่administrator\components\com_virtuemart\classes\ps_product_category.php เปิดไฟล์ ps_product_category.php ขึ้นมา ค้นหาฟังก์ชั่น products_in_category ดังโค้ดด้านล่างนี้
function products_in_category( $category_id ) {
if( PSHOP_SHOW_PRODUCTS_IN_CATEGORY == ‘1′ ) {
$num = ps_product_category::product_count($category_id);
if( empty($num) && ps_product_category::has_childs( $category_id )) {
$db = new ps_DB;
$q = "SELECT category_child_id FROM #__{vm}_category_xref ";
$q .= "WHERE category_parent_id=’$category_id’ ";
$db->query($q);
while( $db->next_record() ) {
$num += ps_product_category::product_count($db->f("category_child_id"));
}
}

return " ($num) ";
}
else
return ( "" [...]

PHP Robot visit

PHP Robot visit

3 September 2008

วันนี้มีโค้ด php แนะนำมาฝาก สำหรับเช็ค robot ที่เข้ามาเก็บข้อมูลจากเว็บไซต์เราไป Index ลง Search Engine เหมาะสำหรัับคนที่ทำ SEO อย่างยิ่งครับ  รายละเอียดและชื่อโปรแกรม วิธีการติดตั้ง อยู่ด้านล่างนี้ครับ
PHP Robot Visit
http://www.stevedawson.com/downloads/robotvisit.zip
Check when the search engines are visiting your website
Author: Steve Dawson ผู้พัฒนา

Download PHP Robot Visit Script

How to Find & Replace Data in MySQL

How to Find & Replace Data in MySQL

17 August 2008

To find a string in a certain field and replace it with another string:

update [table_name] set [field_name] = replace([field_name],’[string_to_find]‘,’[string_to_replace]‘);

Credit http://www.mediacollege.com/computer/database/mysql/find-replace.html

MySQL SUM – Totaling Groups

MySQL SUM – Totaling Groups

15 August 2008

ตัวอย่างตาราง

id
name
type
price

123451
Park’s Great Hits
Music
19.99

123452
Silly Puddy
Toy
3.99

123453
Playstation
Toy
89.95

123454
Men’s T-Shirt
Clothing
32.50

123455
Blouse
Clothing
34.97

123456
Electronica 2002
Music
3.99

123457
Country Tunes
Music
21.55

123458
Watermelon
Food
8

MySQL SUM – Totaling Groups

SUM is an aggregate function that totals a specific column for a group. The “products” table that is displayed above has several products of various types. One use of SUM might be to find the total of all the items’ price for each product type.
Just [...]

OScommerce 1054-problem

OScommerce 1054-problem

5 August 2008

In Catalog/index.php file..
Find this…
// show the products of a specified manufacturer
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
if (isset($HTTP_GET_VARS['filter_id']) &amp;&amp; tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only a specific category
$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p, " [...]

phpMyAdmin เวอชั่นเก่าๆ

phpMyAdmin เวอชั่นเก่าๆ

25 June 2008

วันนี้ทำเว็บ ย้าย Server ลูกค้าติดปัญหาหลายเรื่องเกี่ยวกับฐานข้อมูล phpMyAdmin เวอร์ชั่นใหม่มันเยอะเล่นไม่ถนัดมือ เลยไปหาเวอร์ชั่นเก่ามาเล่น  ไปลองค้นหาจากเว็บผู้พัฒนาก็เจอแต่ยังเก่าไม่พอ เลย search google ไปเรื่อยๆไปเจอเข้าเลยเอามาฝากกัน สำหรับใครที่สนใจที่จะใช้เวอร์ชั่นเก่า  ดาวน์โหลดได้ที่นี่ครับ http://ftp.ksu.edu.tw/FTP/Unix/Web/phpMyAdmin/
ส่วนตัวผมเองจะชอบใช้ที่เวอรชั่น 2.5.4 หรือไม่ก็ 2.5.6 เท่านั้นครับ
ดาวน์โหลด 2.5.4

PHP คำนวณหาระยะห่างระหว่างวันที่

PHP คำนวณหาระยะห่างระหว่างวันที่

22 June 2008

โค้ดโปรแกรม
<?php
####### รูปแบบของวันที่ ที่อาจจะเก็บลงในฐานข้อมูลแบบนี้ ######
$start_date=”17/03/2007″; // วันที่เริ่มใช้บริการ
$expire_date=”17/03/2008″;//วันสิ้นสุดการใช้บริการ
$today_date=date(”d/m/Y “);//วันที่ของวันนี้
## ฟังก์ชั่น explode ใช้แยกเครื่องหมาย ( / ) ออกจากข้อความ แล้วเอาข้อความที่ได้ไปแยกเก็บลงใน array ##
/* วันที่เริ่มใช้บริการ */
$start_explode = explode(”/”, $start_date);
$start_day = $start_explode[0];
$start_month = $start_explode[1];
$start_year = $start_explode[2];
/*วันสิ้นสุดการใช้บริการ*/
$expire_explode = explode(”/”, $expire_date);
$expire_day = $expire_explode[0];
$expire_month = $expire_explode[1];
$expire_year = $expire_explode[2];
/*วันที่ของวันนี้*/
$today_explode = explode(”/”, $today_date);
$today_day = $today_explode[0];
$today_month = $today_explode[1];
$today_year = $today_explode[2];
/* ฟังก์ชั่น gregoriantojd เป็นฟังก์ชั่นที่เอาไว้แปลงวันที่ เพื่อใช้คำนวณหาจำนวนวัน
รูปแบบการใช้งาน gregoriantojd ( int $month, int [...]

ขั้นตอนการลง AppServ + Eclipse + Zenddebugger สำหรับคนที่ต้องการเริ่มเขียน PHP

ขั้นตอนการลง AppServ + Eclipse + Zenddebugger สำหรับคนที่ต้องการเริ่มเขียน PHP

22 June 2008

Quote
1. ขั้นตอนการลง AppServ + Eclipse + Zenddebugger สำหรับคนที่ต้องการเริ่มเขียน PHP
2. สอนเขียน PHP
3. help file
http://www.zend.com/en/community/pdt
http://www-128.ibm.com/developerworks/ibm/…&ca=dkw-php
สมัยก่อนใช้แต่ editplus ตอนนี้มี debugger ใช้แล้วเท่ห์จิงๆ
แหล่งที่มา http://www.witcomram.com/webboard/index.php?showtopic=6260
โดยคุณ dragon_html [at] witcomram.com
http://www.thaihosttalk.com/th1/index.php?topic=10333.0

How to make your own PHP template script

How to make your own PHP template script

21 March 2008

Many people ask how do you create a template system in PHP. It is true their are many different ways, but this will hopefully show you the basic understanding of this type of method.
First, let us understand the varibles in both the main .html page, and in the php scripts.
In this example <% main %> [...]

Ban IP from opening HTML page with PHP

Ban IP from opening HTML page with PHP

20 March 2008

ban.php (replace €€€€€€ by the redirection URL, for example a void page an image or anything else) <?php
$filename = “ban.txt”;
$handle = fopen($filename, “r”);
$string = fread($handle, filesize($filename));
fclose($handle);
$sArr = explode(”\n”,$string);
//get user IP address
$userip = $_SERVER['REMOTE_ADDR'];
//check for banned IP address
if (in_array($userip, $sArr)) {
echo “<script type=\”text/javascript\” language=\”javascript\”>”;
echo “window.open(\”€€€€€€\”,\”_top\”);”;
echo “</script>”;
}
?>

MySQL COUNT – Counting Records

MySQL COUNT – Counting Records

20 March 2008

Products Table:

id
name
type
price

123451
Park’s Great Hits
Music
19.99

123452
Silly Puddy
Toy
3.99

123453
Playstation
Toy
89.95

123454
Men’s T-Shirt
Clothing
32.50

123455
Blouse
Clothing
34.97

123456
Electronica 2002
Music
3.99

123457
Country Tunes
Music
21.55

123458
Watermelon
Food
8.73

PHP and MySQL Code:
<?php
// Make a MySQL Connection
 $query = “SELECT type, COUNT(name) FROM products GROUP BY type”;
 $result = mysql_query($query) or die(mysql_error());
// Print out result while($row = mysql_fetch_array($result))
{ echo “There are “. $row['COUNT(name)'] .” “. $row['type'] .” items.”;  
echo “<br />”;  }
 ?>
Display:
There are 2 Clothing items.
There are 1 Food [...]

Reading URL Function

Reading URL Function

20 March 2008

$_SERVER['FULL_URL'] = ‘http’;
$script_name = ”;
if(isset($_SERVER['REQUEST_URI'])) {
$script_name = $_SERVER['REQUEST_URI'];
} else {
$script_name = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']>’ ‘) {
$script_name .= ‘?’.$_SERVER['QUERY_STRING'];
}
}
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']==’on’) {
$_SERVER['FULL_URL'] .= ’s’;
}
$_SERVER['FULL_URL'] .= ‘://’;
if($_SERVER['SERVER_PORT']!=’80′) {
$_SERVER['FULL_URL'] .=
$_SERVER['HTTP_HOST'].’:’.$_SERVER['SERVER_PORT'].$script_name;
} else {
$_SERVER['FULL_URL'] .= $_SERVER['HTTP_HOST'].$script_name;
}echo $_SERVER['FULL_URL'];

ADMIN : DB function failed with error number 1054

ADMIN : DB function failed with error number 1054

20 March 2008

เข้า admin แล้ว
เข้าที่เมนู Contens> All Content Items มี error ดังนี้
DB function failed with error number 1054
Unknown column ‘c.access’ in ‘on clause’ SQL=SELECT c.*, g.name AS groupname, cc.name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author FROM mos_content AS c, mos_categories AS cc, mos_sections AS s LEFT JOIN mos_groups AS g ON g.id [...]

How to Reset the Products Viewed Report

How to Reset the Products Viewed Report

20 March 2008

This below SQL command for reset products viewer of oscmax 
UPDATE products_description SET products_viewed = 0

PHP upload_max_filesize

PHP upload_max_filesize

18 May 2007

This is the .htaccess code:

php_value upload_max_filesize 50M
php_value max_execution_time 800

เช็คโค้ดเช็คบัตรประชาชน

เช็คโค้ดเช็คบัตรประชาชน

28 October 2006

<script language=”javascript”>
function makearray(n)
{
this.length=n;
for( var i=0; i < n ; i++)
this[i] = 0;
return this;
}
function chkIDcard(){
var xCheck = 0;
var g = 0;
var c = 0;
var totalX = 0;
var sumX = 0;
var x = new makearray(13);
var z=”0″;
var l=”0″;
if(form1.idCard.value.length !=13){
alert(’บัตรผิด ต้อง 13 ตัวเท่านั้น’);
return false;
}else
if ( form1.idCard.value.length > 1 )
{
for (var q=0; q<form1.idCard.value.length; ++q)
{
var codee=form1.idCard.value.charCodeAt(q);
// if (codee>=48 && codee<=57)continue ;
if [...]

How to update multiple rows in mysql with php

How to update multiple rows in mysql with php

25 October 2006

Here comes my first geeky php post. For people who have basic knowledge in updating mysql information through a php form, you’ll notice that almost all of the tutorials only tell you how to update ONE record at a time. Well, I figured it must be a simple tweak to update multiple records. Unfortunately, I [...]