Php 使用mysql_fetch_array()和foreach()显示结果时,本地Apache服务器崩溃

Php 使用mysql_fetch_array()和foreach()显示结果时,本地Apache服务器崩溃,php,apache,foreach,Php,Apache,Foreach,所以,基本上我要做的就是在页面上显示搜索点击率。我已经设置了一个表单,发布到下面的页面,然后在我的MySQL数据库中搜索这些数据,结果应以以下格式显示: 名称 轮廓图像路径 年龄 我在互联网上进行了广泛的搜索,发现必须使用while循环,因为我以前只是使用foreach循环 但每当我搜索某个东西时,我的apache服务器就会崩溃。我认为这可能是因为while循环,因为它以前没有崩溃,但它只会显示一定次数的相同的结果集(名称、图像和年龄),具体取决于数据库中找到的行数 以下是搜索页面

所以,基本上我要做的就是在页面上显示搜索点击率。我已经设置了一个表单,发布到下面的页面,然后在我的MySQL数据库中搜索这些数据,结果应以以下格式显示:



名称
轮廓图像路径
年龄



我在互联网上进行了广泛的搜索,发现必须使用while循环,因为我以前只是使用foreach循环

但每当我搜索某个东西时,我的apache服务器就会崩溃。我认为这可能是因为while循环,因为它以前没有崩溃,但它只会显示一定次数的相同的结果集(名称、图像和年龄),具体取决于数据库中找到的行数

以下是搜索页面代码:

require_once "lib/mysql.php";
if(设置($\u POST[search])&&!空($\u POST[search])){

$search=$\u POST[search];
//用于函数的mysql类。
$mysql=新的mysqlHandle;
//打开对mysql服务器的访问。
$mysql->accessOpen('root','Portfolio','localhost');
//将$rows设置为“Name”值为$search的条目数(行)。
$rows=$mysql->tableCheckNum('*',stats,Name,$search,Portfolio);
回声“
“$Search”的搜索结果



; //确保至少有1次搜索命中。 如果($rows>0){ //设置当前命中数。(第一个为1,第二个为2 et.c) $num=1; $user=array(); //My mysql函数用于检查条目的顺序,请参阅随附的myqsl代码。 而($result=$mysql->tableCheckOrder('*',stats,Name,$search,ID,DESC,Portfolio)){ //$user数组应该保存用户(搜索到的)详细信息。 $user[]=$result; foreach($user as$result){ //确保没有超过行数。
如果($num)“撞车”是什么意思?apache进程是否终止?确切的错误消息是什么?请检查/var/log/apache2/中的apache或php错误日志。浏览器地址/url部分中的进度条刚刚停止,我的计算机开始过热,我与PHPmyadmin失去连接。我想您永远处于循环中。您也可以使用$result.y执行某些操作我们在循环中一次又一次地使用它。危险..您应该更改:$users[]=$result;尝试一下,但对我来说,这是因为您在一个无限循环中。foreach($users as$user){检查当您遇到r崩溃时apache进程是否消耗100%的CPU。另外,请阅读,您的SQL/PHP混合很容易发生SQL注入(提示:我搜索
”;删除表统计信息;--
。谢谢。我计划在基本代码启动并运行后保护它:)
$search = $_POST[search];

// The mysql class used for functions.

$mysql = new mysqlHandle;

// Opens access to the mysql server.

$mysql->accessOpen('root', '', 'Portfolio', 'localhost');

// Sets $rows to number of entries (rows) with the 'Name' value of $search.

$rows = $mysql->tableCheckNum('*', stats, Name, $search, Portfolio);

echo "<div id='content'>
    <div id='content_main'>
        <h2>Search Results for '$search'</h2>
        <br/><hr/><br/>";

// Makes sure that there's at least 1 search hit.

if ($rows>0){

    // Sets the current hit number. (the first one is 1, the second is 2 et.c)

    $num = 1;

    $user = array();

    // My mysql function for checking the order of entries, see the attached myqsl code.

    while ($result = $mysql->tableCheckOrder('*', stats, Name, $search, ID, DESC, Portfolio)){

        // The $user array should hold the user's (searched for) details.

        $user[] = $result;

        foreach ($user as $result){

        // Makes sure that we haven't exceeded the number of rows.

            if ($num<=$rows){

            // Adds one to the number of displayed rows, as we have dsplayed another.

                $num++;

            // Prints the user's (searched for) details.

                print_r ($user[Name]."<br/>");
                print_r ($user[Image]."<br/>");
                print_r ($user[Age]."<br/>"."<br/>"."<hr/>"."<br/>");

            }

        }               
    }

}else{

    echo "No users found";

}

echo '</div>
    </div>';
// Gets order of entries (rows) The indentations under "function tableCheckOrder" isn't showing up btw.
    function tableCheckOrder($span, $table, $column, $value, $order, $mode, $base){

    mysql_select_db($base);

    $this->query11="SELECT $span FROM $table WHERE $column = '$value' ORDER BY $order $mode";
    $this->result11=mysql_query($this->query11) or die("<br/>"."Invalid $table CHECK ORDER query: " .mysql_error());

    return mysql_fetch_array($this->result11, $result_type = MYSQL_BOTH);

}

// This function checks amount of rows in table.

function tableCheckNum($span, $table, $column, $value, $base){

    mysql_select_db($base);

    $this->query="SELECT $span FROM $table WHERE $column = '$value'";
    $this->result=mysql_query($this->query) or die("Invalid $table CHECK NUM query: " .mysql_error());

    return mysql_num_rows($this->result);

}