php搜索查询只输出两个结果…而不是整行

php搜索查询只输出两个结果…而不是整行,php,mysql,Php,Mysql,大家好,我在index.html中有一个搜索查询。当用户按search时,它会转到searchjobs.php 我希望它输出整行。那是 工作证 职位 工作描述 工作地点 工作类别 目前,它只输出其中的两个字段,即职务头衔和职务描述。如何使其输出整行?例如,如果此人搜索“Leeds”,我希望它输出关于Leeds中工作的整行 我认为问题出在回声区 如果我在php脚本中输入更多变量…它将不会运行 <?php mysql_connect("*****", "root", "*****")

大家好,我在index.html中有一个搜索查询。当用户按search时,它会转到searchjobs.php

我希望它输出整行。那是 工作证 职位 工作描述 工作地点 工作类别

目前,它只输出其中的两个字段,即职务头衔和职务描述。如何使其输出整行?例如,如果此人搜索“Leeds”,我希望它输出关于Leeds中工作的整行

我认为问题出在回声区

如果我在php脚本中输入更多变量…它将不会运行

<?php
    mysql_connect("*****", "root", "*****") or die("Error connecting to database: ".mysql_error());
    /*

        if connection fails it will stop loading the page and display an error
    */

    mysql_select_db("jobslist") or die(mysql_error());
    /* tutorial_search is the name of database we've created */


    $query = $_GET['query'];
    // gets value sent over search form

    $min_length = 4;
    // you can set minimum length of the query if you want

    if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then

        $query = htmlspecialchars($query);
        // changes characters used in html to their equivalents, for example: < to &gt;

        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection

        $raw_results = mysql_query("SELECT * FROM jobs_list
            WHERE (`job_title` LIKE '%".$query."%') OR (`job_location` LIKE '%".$query."%')") or die(mysql_error());

        // * means that it selects all fields, you can also write: `id`, `title`, `text`
        // jobs_list is the name of our table

        // '%$query%' is what we're looking for, % means anything, for example if $query is Hello
        // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
        // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

        if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

            while($results = mysql_fetch_array($raw_results)){
            // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop

                echo "<p><h3>".$results['job_id']."</h3>"
                              .$results['job_title'].
                                .$results['job_description'].
                                .$results['job_location'].
                                .$results['job_category'].



                           "</p>";
                // posts results gotten from database you can also show id ($results['id'])
            }

        }
        else{ // if there is no matching rows do following
            echo "No results";
        }

    }
    else{ // if query length is less than minimum
        echo "Minimum length is ".$min_length;
    }
?>

如果在变量的两侧都使用了凝聚点,请删除多余的点:

echo '<p><h3>'.$results['job_id'].'</h3>'
     . $results['job_title']
     . $results['job_description']
     . $results['job_location']
     . $results['job_category']
     . '</p>';
echo'。$results['job\u id'.'
. $结果[“职务”]
. $结果[“工作描述”]
. $结果[“工作地点”]
. $结果[“工作类别”]
. '

",;
我假设你目前正在测试和尝试,否则你应该适当地组织你的工作描述

$tplJob= '<div class="job_entry">
  <h3>ID: %s</h3>
  <div class="title">%s</div>
  <div class="description">%s</div>
  <div class="location">Location: %s</div>
  <div class="category">Category: %s</div>
</div>';

// echo formatted output based on above template variable
echo sprintf($tplJob, $results['job_id'], $results['job_title'],  $results['job_description'], $results['job_location'], $results['job_category']);
$tplJob='1
ID:%s
%
%
位置:%s
类别:%s
';
//基于上述模板变量的echo格式化输出
echo sprintf($tplJob、$results['job_id']、$results['job_title']、$results['job_description']、$results['job_location']、$results['job_category');
var_dump($results)中有什么内容?请停止使用mysql,开始使用PDO或mysqli_