我有一个遍历表的 while 循环,我在其中回显结果,我还有一个查看图像目录的 while 循环,我可以输出图像的路径。我的问题是我想在我的 html 和图像标记所在的另一个 while 循环中输出图像路径。我曾尝试将一个 while 循环放在另一个循环中,但 while 中的一个结果是重复的。如何将变量放在图像的第一个 while 循环之外,并将其放在另一个 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 />";
/ ------------------抓取表单数据---------------------------- - /
$name = $_POST['name'];
$about = $_POST['about'];
$company = $_POST['company'];
$buy = $_POST['buy'];
$tags = $_POST['tags'];
$imageName1 = $_FILES["file"]["name"];
/ ------------------插入数据库--------------------- /
$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 />";
}