PHP,构建一个基本的动态插入字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP,构建一个基本的动态插入字符串相关的知识,希望对你有一定的参考价值。
Makes basic insert statements a breeze to type while doing basic php inserts.\r\n*The function for \\\'querys\\\' on line 44 can be found here: http://snipplr.com/view/40911/query-the-database-php/ *
//Insert //$sql = "INSERT INTO quick_links (title, link) VALUES('" . $_POST['title'] . "', '" . $link . "');"; function add($table, $columns, $values){ //begin the insert into******************************************************* $sql = "INSERT INTO " . $table; //iterate through the $table************************************************** //iterate through the $columns *********************************************** $sql = $sql . " (" . $columns . ") VALUES("; //iterate through the $values************************************************* //loop the array foreach($arrValue as $arrValueResult){ //check if last index in array $arrValueResult = $arrValueResult ; }else{ $arrValueResult = "'" . $arrValueResult . "'" ; } }else{ $arrValueResult = $arrValueResult . ", " ; }else{ $arrValueResult = "'" . $arrValueResult . "', " ; } }//end if //add to $sql $sql = $sql . $arrValueResult; }//end for each //end the $sql $sql = $sql . ");"; //determine is item in $values is an interger / string //echo $sql; //insert the query $insert_sql = querys($sql); }//end add //----------------------------------------------------------------- //To use this function: $add_cat = add("categories", "cat", $_POST['cat']);
以上是关于PHP,构建一个基本的动态插入字符串的主要内容,如果未能解决你的问题,请参考以下文章
html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。