Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将php变量发送到另一个php页面_Php_Mysql_Html - Fatal编程技术网

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

将php变量发送到另一个php页面,php,mysql,html,Php,Mysql,Html,我需要一些编码方面的帮助。我有一个名为index.php的页面和一个picture.php index.php 我只指定了5作为用于从数据库检索图像的id。这是因为我不知道如何从index.php中获取$pid,并将其分配给一个可以在SQL查询中使用的变量 任何帮助都将不胜感激。提前感谢。您可以将其包含在picture.php的查询字符串中,例如: echo '<a id="various3" href="picture.php?id=', $pid, '" ... '; index.p

我需要一些编码方面的帮助。我有一个名为
index.php
的页面和一个
picture.php

index.php 我只指定了5作为用于从数据库检索图像的id。这是因为我不知道如何从
index.php
中获取
$pid
,并将其分配给一个可以在SQL查询中使用的变量


任何帮助都将不胜感激。提前感谢。

您可以将其包含在picture.php的查询字符串中,例如:

echo '<a id="various3" href="picture.php?id=', $pid, '" ... ';
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>';
}

for($ctr=1;$ctr不在数据库中存储图片,只保存名称。
您不需要在任何地方传递任何内容,并且可以避免代码中的其他愚蠢错误

让你的主页像这样

<?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>';
} 
?>


仅此而已

您是使用ajax抓取picture.php?还是只是将页面作为一个完整的常规页面加载?我不使用ajax..也是因为我不知道如何使用..伙计,如果我使用$ctr而不是$pid,当达到条件$ctr时,计数将返回到零。为什么会返回到零?我只是在打印它。欢迎您,jaja
if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
    // todo: some proper error handling
    exit;
}
$sql = "select pics, ext from infopics where id=" . $_GET['id'];
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>';
}
<?php
...
$sql = sprintf("select pics, ext from infopics where id='%d'", $_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>';
} 
?>