php:使用变量名在不同页面上显示特定图像

php:使用变量名在不同页面上显示特定图像,php,html,mysql,sql,Php,Html,Mysql,Sql,这里是Php初学者。我在页面上有php循环来显示图像(基本上是一个图库),每个图像都有一个标题显示在下面。这些标题是指向第二页的链接,其中只显示一幅图像。 问题是每个链接都有不同的名称(名称的值是特定的/ID图像) 提前感谢您的帮助。将查询更改为: $sql_select = "SELECT * FROM images WHERE ID =" $_GET['id']; 将查询更改为: $sql_select = "SELECT * FROM images WHERE ID =" $_GET['

这里是Php初学者。我在页面上有php循环来显示图像(基本上是一个图库),每个图像都有一个标题显示在下面。这些标题是指向第二页的链接,其中只显示一幅图像。 问题是每个链接都有不同的名称(名称的值是特定的/ID图像)

提前感谢您的帮助。

将查询更改为:

$sql_select = "SELECT * FROM images WHERE ID =" $_GET['id'];
将查询更改为:

$sql_select = "SELECT * FROM images WHERE ID =" $_GET['id'];
不需要表格

第一个脚本:

<?php
$sql_select = "SELECT * FROM images ORDER BY data DESC"; 
$sql_table_selected = mysql_query($sql_select);
while ($table_row = mysql_fetch_array($sql_table_selected)){
    echo "<div class=\"galery-1-3\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption><a href=\"image_link.php?id=" . $table_row['ID'] 
     . "\" name=\"" . $table_row['ID']
     . "\">" . $table_row['tytul'] . "</a></figcaption></figure></div>";
}
?>

第二稿

$SomehowGetID=$_GET['id'];
$sql_select = "SELECT * FROM images WHERE ID = $SomehowGetID"; 
$sql_table_selected = mysql_query($sql_select); 
$table_row = mysql_fetch_array($sql_table_selected);
    echo "<div class=\"galery-big\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption>" . $table_row['tytul'] 
    . "</figcaption></figure>   </div>";
$SomehowGetID=$\u GET['id'];
$sql\u select=“从图像中选择*,其中ID=$SomehowGetID”;
$sql\u table\u selected=mysql\u query($sql\u select);
$table\u row=mysql\u fetch\u数组($sql\u table\u selected);
回声“;
回声“;
“回声”$表_第['tytul'行]
. "   ";
不过,我建议您使用预先准备好的语句,而不是简单的查询结构。

不需要表单

echo 
"<figcaption>
<a href='image_link.php?id=$table_row[ID]' name='$table_row[ID]'>"
 .$table_row['tytul'] ."
</a>
</figcaption>
</figure></div>";
第一个脚本:

<?php
$sql_select = "SELECT * FROM images ORDER BY data DESC"; 
$sql_table_selected = mysql_query($sql_select);
while ($table_row = mysql_fetch_array($sql_table_selected)){
    echo "<div class=\"galery-1-3\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption><a href=\"image_link.php?id=" . $table_row['ID'] 
     . "\" name=\"" . $table_row['ID']
     . "\">" . $table_row['tytul'] . "</a></figcaption></figure></div>";
}
?>

第二稿

$SomehowGetID=$_GET['id'];
$sql_select = "SELECT * FROM images WHERE ID = $SomehowGetID"; 
$sql_table_selected = mysql_query($sql_select); 
$table_row = mysql_fetch_array($sql_table_selected);
    echo "<div class=\"galery-big\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption>" . $table_row['tytul'] 
    . "</figcaption></figure>   </div>";
$SomehowGetID=$\u GET['id'];
$sql\u select=“从图像中选择*,其中ID=$SomehowGetID”;
$sql\u table\u selected=mysql\u query($sql\u select);
$table\u row=mysql\u fetch\u数组($sql\u table\u selected);
回声“;
回声“;
“回声”$表_第['tytul'行]
. "   ";

我建议您使用预先准备好的语句,而不是简单的查询结构。

您的想法是正确的,您希望传递图像的id。
echo 
"<figcaption>
<a href='image_link.php?id=$table_row[ID]' name='$table_row[ID]'>"
 .$table_row['tytul'] ."
</a>
</figcaption>
</figure></div>";
您的代码应该如下所示:

<form action="image_link.php" method="post">
<?php>
$sql_select = "SELECT * FROM images ORDER BY data DESC"; 
$sql_table_selected = mysql_query($sql_select);
while ($table_row = mysql_fetch_array($sql_table_selected)){
    echo "<div class=\"galery-1-3\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption><a href=image_link.php?id=" . intval($table_row['ID']) . "name=\"" . $table_row['ID'] . "\">" . $table_row['tytul'] . "</a></figcaption></figure></div>";
    }
?>

image_link.php:

$sql_select = "SELECT * FROM images WHERE ID =" . mysql_real_escape_string($_GET['id']); 
$sql_table_selected = mysql_query($sql_select);
$table_row = mysql_fetch_array($sql_table_selected);
echo "<div class=\"galery-big\"><figure>";
echo "<img src=\"" . $table_row['file_path'] . "\" />";
echo "<figcaption>" . $table_row['tytul'] . "</figcaption></figure></div>";
$sql\u select=“从图像中选择*,其中ID=”。mysql_real_escape_字符串($_GET['id']);
$sql\u table\u selected=mysql\u query($sql\u select);
$table\u row=mysql\u fetch\u数组($sql\u table\u selected);
回声“;
回声“;
“回声”$表_第['tytul'行]。"";

请注意,mysql_*函数的使用是非常不受欢迎的,您应该使用mysqli扩展来代替

您的想法是正确的,您希望传递图像的id。 您的代码应该如下所示:

<form action="image_link.php" method="post">
<?php>
$sql_select = "SELECT * FROM images ORDER BY data DESC"; 
$sql_table_selected = mysql_query($sql_select);
while ($table_row = mysql_fetch_array($sql_table_selected)){
    echo "<div class=\"galery-1-3\"><figure>";
    echo "<img src=\"" . $table_row['file_path'] . "\" />";
    echo "<figcaption><a href=image_link.php?id=" . intval($table_row['ID']) . "name=\"" . $table_row['ID'] . "\">" . $table_row['tytul'] . "</a></figcaption></figure></div>";
    }
?>

image_link.php:

$sql_select = "SELECT * FROM images WHERE ID =" . mysql_real_escape_string($_GET['id']); 
$sql_table_selected = mysql_query($sql_select);
$table_row = mysql_fetch_array($sql_table_selected);
echo "<div class=\"galery-big\"><figure>";
echo "<img src=\"" . $table_row['file_path'] . "\" />";
echo "<figcaption>" . $table_row['tytul'] . "</figcaption></figure></div>";
$sql\u select=“从图像中选择*,其中ID=”。mysql_real_escape_字符串($_GET['id']);
$sql\u table\u selected=mysql\u query($sql\u select);
$table\u row=mysql\u fetch\u数组($sql\u table\u selected);
回声“;
回声“;
“回声”$表_第['tytul'行]。"";

请注意,mysql_*函数的使用是非常不受欢迎的,您应该改用mysqli扩展

我在
image_link.php&id
中不得不使用问号而不是符号,我不知道为什么,但它起了作用。谢谢我的错,是的,它是一个“?”,我会修改它。我不得不在
image\u link.php&id
中使用问号而不是符号,我不知道为什么,但它起了作用。谢谢我的错,是的,它是一个“?”,我会修改它。为什么他不能这样学习?如果他想用这种方式玩游戏,问题是什么?安全将是主要关注点。我没有说答案有任何问题,但这是更好的练习。同意是的,准备好的陈述是最好的练习。他为什么不能这样学习?如果他想用这种方式玩游戏,问题是什么?安全将是主要关注点。我没有说答案有任何问题,但这是更好的做法。同意是,准备好的陈述是最佳做法。