ファイル名の一部をphpのmy sqlクエリのパラメータとして渡そうとしています。私のファイル名は db_feature_T1..iOXXdrXXcAMEra_092521.txt の形式で、そこから db_feature と .txt を除く部分、つまり T1..iOXXdrXXcAMEra_092521 が必要です。
img_path=dressimages/T1..iOXXdrXXcAMEra_092521.jpg のデータベースから img_id が欲しい
私のコードは次のとおりです。ファイル名を区切ることはできましたが、データベースから結果を取得できません。
<?php
include('db.php');
if ($handle = opendir('C:\Users\adithi.a\Desktop\db_features')) {
while (false !== ($entry = readdir($handle))) {
$entry=substr($entry,11,-4); //this seperates the file name db_feature_T1..iOXXdrXXcAMEra_092521.txt to T1..iOXXdrXXcAMEra_092521
$image_path='dressimages/'.$entry.'.jpg';//I want to pass the img_path as it is saved in the database in the form of dressimages/T1..iOXXdrXXcAMEra_092521.jpg
$result= mysql_query("select img_id from tbl_image where img_path='$image_path'") or die("Sorry");
echo $result;//I dont get anything as output.
}
}
closedir($handle);
?>
上記のコードを実行すると無限ループに陥ったので、試しました:
$image_path='dressimages/'.$entry.'.jpg';//I want to pass the img_path as it is saved in the database in the form of dressimages/T1..iOXXdrXXcAMEra_092521.jpg
$sql = "select img_id from tbl_image where img_path=".$image_path;
echo $sql . '<br />';
$result=mysql_query("$sql");
}
while($data=mysql_fetch_assoc($result))
{
echo $data["img_id"];
}
そして今、私はエラー mysql_fetch_assoc() がパラメーター 1 をリソース、ブール値で指定された C:\wamp\www\FashionBonanza\Readfile.php の 34 行目に表示します
どんな助けでも