我有一個while循環遍歷一個表,並且我在其中回顯結果,我也有一個while循環查看圖像目錄,我可以輸出圖像的路徑。我的問題是我想在我的HTML和圖像標籤所在的其他while循環中輸出圖像路徑。我已經試過把一個while循環放在另一個while循環中,但是這個while while的一個結果會重複。如何在第一次while循環之外獲取圖像的變量,並將其放在另一個while循環中並進行回顯。while while while while loop while
更新我把它工作大家都告訴我,我只是緩慢的正確的事情。我修改了下面的表示抓取表單數據和插入表單數據的代碼,這是我需要做的。
由於
/* LOOP THROUGH IMAGES */
$myDir = dir("images/");
while(($file = $myDir->read()) !==false){
if(!is_dir($file)){
echo "$file";
}
}/*SHOE IMAGE WHILE LOOP ENDS*/
/* LOOP THROUGH SHOEDATA TABLE */
$results = mysql_query("SELECT * FROM shoeData");
while($row = mysql_fetch_array($results)){
$name = $row['name'];
$about = $row['about'];
$company = $row['company'];
$buy = $row['buy'];
$tags = $row['tags'];
$id = $row['id'];
/* ECHO THE SHOEDATA RESULTS */
echo "<div class='span-8'>";
echo "<ul>";
echo "<li>$name</l1>";
echo "<li>$about</l1>";
echo "<li>$company</l1>";
echo "<li><a href='$buy'>BUY</a></l1>";
echo "<li>$tags</l1>";
echo "</ul>";
echo "</div>";
}/*SHOEDATA WHILE LOOP ENDS */
-----------------------UPLOAD SCRIPT UPDATE----------------------
Currently My upload script will move my files but their is nothing currently inputting a field into my database, how would I modify this script to also upload a link to my images in the table with
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
/------------------ GRAB FORM DATA --------------- --------------/
$name = $_POST['name'];
$about = $_POST['about'];
$company = $_POST['company'];
$buy = $_POST['buy'];
$tags = $_POST['tags'];
$imageName1 = $_FILES["file"]["name"];
/------------------ INSERT INTO DATABASE ---- ------------------/
$sql = "INSERT INTO shoeData (name,about,company,buy,tags,image)VALUES(
\"$name\",
\"$about\",
\"$company\",
\"$buy\",
\"$tags\",
\"$imageName1\"
)";
$results = mysql_query($sql)or die(mysql_error());
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
}
}
else
{
echo "Invalid file" . "<br/>";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
}
如何表中的信息與圖像有關?如果兩者之間沒有直接的相關性,那麼有什麼方法可以將它們一起顯示出來? – 2009-11-25 23:52:18
我想以某種方式將ID與圖像名稱相關聯,不知道如何呢? – 2009-11-26 00:04:14
這是一個基本問題。如果您無法將圖像與表格中的每條記錄相關聯,則無法爲特定項目顯示圖像。您只能顯示可能與選定記錄相關或不相關的所有圖像或圖像。鏈接這兩者對於爲用戶提供有用的答案至關重要。 – 2009-11-26 06:41:27