<?php
require_once('db.php');
#keywords table : url_id[medium int] (like bookmark primary key field),
#keyword [varchar], frequency [small int]
function webrec_keywords_get($p_f = '*', $p_extra = ''){
global $webrec_handle;
$query = sprintf("SELECT %s FROM `keywords` %s ",$p_f,$p_extra);
echo "webrec_keywords_get :Query= ".$query."<br />";
$qResult = @mysqli_query($webrec_handle,$query);
if(!$qResult){
@mysqli_free_result($qResult);
echo "error in query for webrec_keywords_get function<br/>";
return NULL;
}
$rCount = mysqli_num_rows($qResult);
//echo $rCount;
if($rCount == 0){ //when there is no rows as result for the specific query above
@mysqli_free_result($qResult);
return 0;
}
$keywords = array();
for($i = 0; $i <$rCount; $i++)
$keywords[$i] = @mysqli_fetch_assoc($qResult);
@mysqli_free_result($qResult);//clean the result from memory, it is have been saved in $keywords array
//var_dump($users );
return $keywords;
}
function webrec_keywords_getByUrlId($uId){
$result = webrec_keywords_get('*','WHERE `url_id` ='. $uId);
return $result;
}
//keyword table :
// | url_id [mediumint] not null| keyword [varchar(80)] not null| frequency [smallint(5)] not null
function webrec_keywords_add_All($p_urlId, $p_keywordArray) {
global $webrec_handle;
$length = count($p_keywordArray);
$i = 0;
//echo $length . '<br/>';
if( empty($p_urlId) ||empty($p_keywordArray) )
return FALSE; //return array(FALSE,'Requirement: one or more of the fields have empty value');
$query = "INSERT INTO `keywords` (`url_id`, `keyword`, `frequency`) VALUES ";
foreach($p_keywordArray as $key => $frequency){
$trimed_keyword = trim($key); // remove spaces from the beginning and end of string
if( $trimed_keyword !== '' && $trimed_keyword !== ' ' && $trimed_keyword !== null){
$temp = sprintf("(%d,'%s',%d)",$p_urlId, $trimed_keyword, $frequency);
$query = $query . $temp;
if(( $i+1 ) < $length ) //if there is another array member, add a comma
$query = $query . ',' ;
$i = $i + 1;
}
}
echo "webrec_keywords_add_All :Query= ".$query."<br />";
$qResult = @mysqli_query($webrec_handle, $query);
if(!$qResult){
//echo mysqli_error($webrec_handle);
@mysqli_free_result($qResult);
return NULL;//return array(NULL,'Error : failed executing add keywords function because : '.mysqli_error($webrec_handle));
}
@mysqli_free_result($qResult);
return TRUE;
}
################################################################################################################
//add keywords for specific url_id - [webrec_keywords_add] function
//INSERT INTO `finalproject_2`.`keywords` (`url_id`, `keyword`, `frequency`) VALUES ('52', 'game', '4'),
//('53', 'player', '4'),('54', 'book', '3'),('55', 'novel english', '3'),('56', 'movie', '7');
//INSERT INTO `finalproject_2`.`keywords` (`url_id`, `keyword`, `frequency`)
//VALUES ('52', 'Java', '8'), ('52', 'java', '7') //Duplicate error
/*#1- work fine :
//$u = webrec_keywords_getByUrlId('52');//work good
//$u = webrec_keywords_getByUrlId(51);//work good
//$u = webrec_keywords_get('url_id,keyword,frequency','WHERE `frequency` = 4');//work good
//$u = webrec_keywords_get('*','WHERE `frequency` = 7'); //work good
//$u = webrec_keywords_get('*','WHERE `frequency` = "7"'); //work good
//$u = webrec_keywords_get('*','WHERE `keyword` = "movie"'); //work good
//$u = webrec_keywords_get('*','WHERE `url_id` = 56'); //work good
//$u = webrec_keywords_get(); //work good
if($u > 0 ){
$length = count($u);
echo $length .'<br />';
for($i = 0; $i < $length; $i++){
echo 'url id = '.$u[$i]['url_id'] .', keyword = '.$u[$i]['keyword'].', frequency = '.$u[$i]['frequency'].'<br />';
}
}
else if ($u === 0) echo "no keywords";
else echo "error accourd";
*/
#2- work fine :
/*
$tempArr = array("learn" => 1,"development"=> 10,"gaming"=>7);//correct
//$tempArr = array("learn" => "1","development"=> "10","gaming"=>"7");//correct
$result = webrec_keywords_add_All(100, $tempArr);
if($result === TRUE)
echo 'true<br />';
else if($result === FALSE)
echo 'false<br />';
else echo 'error<br />';
*/
alvarocfc
- 粉丝: 131
- 资源: 1万+
最新资源
- 连接ESP32手表来做验证20241223-140953.pcapng
- 小偏差线性化模型,航空发动机线性化,非线性系统线性化,求解线性系统具体参数,最小二乘拟合 MATLAB Simulink 航空发动机,非线性,线性,非线性系统,线性系统,最小二乘,拟合,小偏差,系统辨
- 好用的Linux终端管理工具,支持自定义多行脚本命令,密码保存、断链续接,SFTP等功能
- Qt源码ModbusTCP 主机客户端通信程序 基于QT5 QWidget, 实现ModbusTCP 主机客户端通信,支持以下功能: 1、支持断线重连 2、通过INI文件配置自定义服务器I
- Linux下TurboVNC+VirtualGL 使用GPU卡vglrun glxgears
- QGroundControl-installer.exe
- Linux下TurboVNC+VirtualGL 使用GPU卡vglrun glxgears
- 台球检测40-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- 颜色拾取器 for Windows
- 数字按键3.2考试代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈