将php变量发送到另一个php页面

我需要一些编码方面的帮助。我有一个名为
index.php
picture.php
的页面。 的index.php
$pid = 0;

for($ctr = 1; $ctr <= 2; $ctr++)
{
    echo '<tr>';
    $pid++;

    echo '<td>';
    echo '<a id="various3" href="picture.php" title="try" idno="5"><img src="picture.php" width="150" height="210">';
    //echo '<br>'.$pagenm;
    echo '</td>';

    echo '</td>';
    echo '</tr>';
}
执行
$pid++
后,我希望将其值发送到
picture.php
,以便它可以用于检索查询。 picture.php
$host = 'localhost';
$user = 'root';
$pw = '';
$db = 'thepillar';

mysql_connect($host, $user, $pw);
mysql_select_db($db);
$sql = "select pics, ext from infopics where id='5'";
// mysql_real_escape_string($sql, mysql_connect);
$result = mysql_query($sql) or die('Bad query at 12!' . mysql_error());
while ( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
    $db_img = $row['pics'];
    $type = $row['ext'];
}
$img = base64_decode($db_img); // print_r($db_img );
$img = imagecreatefromstring($img);
header("Content-Type: image/jpeg");
imagejpeg($img);
imagedestroy($img);
我只分配了5作为用于从数据库中检索图像的id。这是因为我不知道如何从
index.php
获取
$pid
并将其分配给我可以在我的SQL查询中使用的变量。 任何帮助将非常感激。提前致谢。     
已邀请:
的index.php
for($ctr=1; $ctr<=2; $ctr++)
{
     echo '<tr><td><a id="various3" href="picture.php?id=', 
     // I use $ctr insteaf of $pid because is the same... starts with 1
     $ctr,'" title="try" idno="5"><img src="picture.php" width="150" height="210">',
     '</td></td></tr>';
}
picture.php
<?php
...
$sql = sprintf("select pics, ext from infopics where id='%d'", $_GET['id']);
...
?>
    
您可以将它包含在picture.php的查询字符串中,例如:
echo '<a id="various3" href="picture.php?id=', $pid, '" ... ';
然后在picture.php中:
if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
    // todo: some proper error handling
    exit;
}
$sql = "select pics, ext from infopics where id=" . $_GET['id'];
    
不要将图片存储在数据库中,只能保存名称。 你不需要在任何地方传递任何东西,你将避免代码中的其他愚蠢错误。 让你的主页像这样
<?php
$host = 'localhost';
$user = 'root';
$pw = '';
$db = 'thepillar';

mysql_connect($host,$user,$pw); 
mysql_select_db($db); 
$sql = "select pic from infopics limit 2";
$result = mysql_query($sql) or trigger_error(mysql_error().$sql); 
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  echo '<tr>';
  echo '<td>';
  echo '<a id="various3" href="/pictures/'.$row['pic'].'" title="try" idno="5">
        <img src="/pictures/thumbnails/'.$row['pic'].'" width="150" height="210">';
  echo '</td>';
  echo '</tr>';
} 
?>
就这样     

要回复问题请先登录注册