[徵求] 有一點急的問題

看板PHP作者 (幹你娘世界沒真理)時間18年前 (2007/12/09 01:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
要做一個索引的功能 有個index =1,2,3,4 然後資料庫在搜尋的時候 如果和資料庫裡的index欄位(已經打好的)不相等 就跳過 因為我跟PHP比較不熟 所以不知道要加在哪兒 所以想要麻煩各位幫我找一下要加在哪 <?php function input_data() { $main=" <p></p> <form action='{$_SERVER['PHP_SELF']}' method='post'> <p> <textarea name='user_input' cols=20 rows=15 class='textarea'></textarea></p> <input type='hidden' name='op' value='write_data'> <input type='submit' name='btn' value='比對' class='input_btn'> </form>"; return $main; } function write_data() { $fp=fopen("Code/input.txt",w); $content=$_POST['user_input']; fwrite($fp,$content,strlen($content)); fclose($fp); } function lcs() { global $link; global $f_data,$f_len,$s_data,$s_len,$data,$list,$seq_len,$d_count; $show=$_REQUEST['show']; $p=(empty($_REQUEST['p']))?1:$_REQUEST['p']; $num=10; $start=$start=($p-1)*$num; $d_count=0; $filename1=_code_dir."/insong.txt"; change("Code/input.txt",$filename1); $f_data=file($filename1); $f_len=filesize($filename1); $count=count($f_data); if($f_len==0) { $main="你沒有輸入比對資料或輸入資料不正確!"; echo $main; } else { $filename3="Code/compare.txt"; $sql1="select Code,Song_Id from song order by Song_Id;"; $result=mysql_db_query("myweb",$sql1,$link) or die("無法取得資料! <br>".$sql1); $sql1=mysql_query("set names big5"); while($db_data=mysql_fetch_row($result)) { list($Code,$Song_Id)=$db_data; $list[$d_count]=$Song_Id; $s_data=$Code; $s_len=strlen($Code); $lcs=find_lcs($Song_Id); $lcs_len=$lcs[0]; $seq_len[$d_count]=$lcs[1]; $rate=($lcs_len/$f_len)*100; $rate2=round($rate,2); $data[$d_count]=$rate2; $d_count++; } $sql="select count(*) from song"; $result=mysql_db_query("myweb",$sql,$link) or die("無法取得總資料數! <br>".$sql); list($total) = mysql_fetch_row($result); $n=ceil($total/$num); $page_list="<select onChange=\"if(this.value!='') location.href = '{$_SERVER['PHP_SELF']}?op=lcs&p=' + this.value\">"; for($a=1;$a<=$n;$a++){ $selected=($p==$a)?"selected":""; $page_list.="<option value='{$a}' $selected>第 $a 頁</option>"; } $page_list.="</select>"; if($p==$n) $next_page=$p; else $next_page=$p+1; if($p==1) $previous_page=$p; else $previous_page=$p-1; $nav=" <div class='nav'> <a href='{$_SERVER['PHP_SELF']}?op=lcs&p={$previous_page}'>上一頁</a> $page_list <a href='{$_SERVER['PHP_SELF']}?op=lcs&p={$next_page}'>下一頁</a> </div>"; $main="$nav <table class='list'> <tr align='center'> <th nowrap width='90'>專輯封面</th> <th width='180'>音樂</th> <th width='40'>名次</th> <th width='60'>相似度</th> <th width='60'>歌名</th> <th width='50'>演唱者</th> <th width='80'>專輯</th> <th width='50'>長度</th> </tr> </table>"; echo $main; $end=$start+$num; if($end>$d_count) $end=$d_count; for($i=0;$i<$end;$i++) { $main=sorting($d_count,$i); if($i>=$start) echo $main; } echo $nav; } } function sorting($len,$i) { global $link; global $data,$list,$seq_len; $song_list=""; $ok=bubble_sort($len); $sql2="select so.Song_Id,so.Song_Name,si.Singer_Name,a.Album_Name,so.Time,so.Song,a.Picture,so.MV from album a,singer si,song so where so.Song_Id=$list[$i] and so.Album_Id=a.Album_Id and so.Singer_Id=si.Singer_Id"; $result=mysql_db_query("myweb",$sql2,$link) or die("無法取得資料! <br>".$sql2); $db_data=mysql_fetch_row($result); list($Song_Id,$Song_Name,$Singer_Name,$Album_Name,$Time,$Song,$Pic,$MV)=$db_data; $Song=_song_dir."/".$Song; $Pic=_pic_dir."/".$Pic; $Song_Name=stripslashes($Song_Name); $Singer_Name=stripslashes($Singer_Name); $Album_Name=stripslashes($Album_Name); $rank=$i+1; $similar=$data[$i]-(($i+1)*0.025); $similar=round($similar,2); if($similar<0) $similar=0; $song_list="<table class='list'> <tr align='center'> <td width='90' class='func'><img src='{$Pic}' width='80' height='80'></td> <td width='180' style='font-size:12px' valign='middle' nowrap align='center'><br><br> <font class='eng'><u><a href='{$_SERVER['PHP_SELF']}?op=show_lyric&sn={$Song_Id}'>歌曲欣賞 </a></u></font>"; if($MV) $song_list.="<p><font class='eng'><u><a href='{$_SERVER['PHP_SELF']}?op=show_MV&sn={$Song_Id}'>MV欣賞 </a></u></font></p>"; $song_list.="</td> <td width='40' style='font-size:12px' nowrap align='center'>$rank</td> <td width='60' style='font-size:12px' nowrap align='center'>$similar%</td> <td width='60' class='eng' nowrap align='center'>$Song_Name</td> <td width='50' class='eng' nowrap align='center'>$Singer_Name</td> <td width='80' class='eng' nowrap align='center'>$Album_Name</td> <td width='50' style='font-size:12px' nowrap align='center'>$Time</td> </tr> <tr> </tr></table>"; $main="$song_list"; return $main; } function bubble_sort($len) { global $ary,$data,$seq_len; $ary=$data; $flag=1; for($j=$len;$j>0;$j--) if($ary[$j]>=$ary[$j-1]) { if($ary[$j]==$ary[$j-1]) { if($seq_len[$j]>$seq_len[$j-1]) swap($j,$j-1); } else { swap($j,$j-1); $flag=0; } } return $flag; } function swap($x,$y) { global $ary,$data,$list,$seq_len; $temp1=$data[$x]; $data[$x]=$data[$y]; $data[$y]=$temp1; $temp2=$list[$x]; $list[$x]=$list[$y]; $list[$y]=$temp2; $temp3=$seq_len[$x]; $seq_len[$x]=$seq_len[$y]; $seq_len[$y]=$temp3; $temp4=$ary[$x]; $ary[$x]=$ary[$y]; $ary[$y]=$temp4; } function find_lcs($sn) { global $f_data,$f_len,$s_data,$s_len; for($i=1;$i<=$s_len;$i++) { $table[0][$i]=1; } $table[1][0]=0; $table[0][0]=0; $table[1][1]=1; $lcs_seq[0]=0; $lcs_seq[1]=0; $ero=0; $seq=1; $sum=0; $pre=1; for($f_idx=2;$f_idx<=$f_len;$f_idx++) { $flag=0; if($f_idx&1) { $uprow_idx=1; $fillrow_idx=0; } else { $uprow_idx=0; $fillrow_idx=1; } for($s_idx=2;$s_idx<=$s_len;$s_idx++) { if((ord($f_data[0][$f_idx-1]))==ord($s_data[$s_idx-1])) { $table[$fillrow_idx][$s_idx]=$table[$uprow_idx][$s_idx-1]+1; if(($flag==0)&&($table[$fillrow_idx][$s_idx]>$table[$uprow_idx][$s_len])) { $pre=$s_idx; $flag=1; $seq++; } } else if(($flag==0)&&($s_idx>$pre)&&($ero<1)) { if((ord($f_data[0][$f_idx-1]))>=ord($s_dat[$s_idx-1]-2)&&(ord($f_data[0][$f_idx-1]))<=ord($s_data[$s_idx-1])+2) { $table[$fillrow_idx][$s_idx]=$table[$uprow_idx][$s_idx-1]+1; if(($table[$fillrow_idx][$s_idx]>$table[$uprow_idx][$s_len])) { $pre=$s_idx; $flag=1; $seq++; $ero++; } } } else { $up_num=$table[$uprow_idx][$s_idx]; $left_num=$table[$fillrow_idx][$s_idx-1]; $table[$fillrow_idx][$s_idx]=($left_num>=$up_num)?$left_num:$up_num; if($seq>$lcs_seq[1]) { $lcs_seq[1]=$seq; } if(($flag==0)&&($s_idx==$s_len)) { $seq=0; $ero=0; } } } if($seq>$lcs_seq[1]) $lcs_seq[1]=$seq; } $lcs_seq[0]=$table[$fillrow_idx][$s_len]; return $lcs_seq; } function change($filename1,$filename2) { $a=" "; $count=0; $sub[0]=0; $d=0; global $index; $fp1=fopen($filename1,"r"); $fp2=fopen($filename2,"w"); if($fp1!=NULL) { while(!feof($fp1)) { $c=fgetc($fp1); switch($c) { case "c": $b=chr(ord($c)+4);break; case "d": $b=chr(ord($c)+5);break; case "e": $b=chr(ord($c)+6);break; case "f": $b=chr(ord($c)+6);break; case "g": $b=chr(ord($c)+7);break; case "a": $b=chr(ord($c)+15);break; case "b": $b=chr(ord($c)+16);break; case "!": $index=1; case "@": $index=2; case "$": $index=3; case "%": $index=4; } if($a=="#") $b=chr(ord($b)+1); else if((49<=ord($c))&&(ord($c)<=51)&&(97<=ord($a))&&(ord($a)<=103)) { switch($c) { case "1":$b=chr(ord($b)-12); break; case "2":$b=$b; break; case "3":$b=chr(ord($b)+12); break; } if($count>0) $sub[$count]=ord($b)-ord($d); $e=chr($sub[$count]+83); fputs($fp2,$e); $d=$b; $count++; } $a=$c; } } fclose($fp1); fclose($fp2); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.189.211
文章代碼(AID): #17MixY6R (PHP)
文章代碼(AID): #17MixY6R (PHP)