Results 1 to 2 of 2

Thread: Display multiple columns on results display...

  1. #1
    Join Date
    Dec 2012

    Display multiple columns on results display...

    Hi everybody,

    I'm trying to display three columns of data when the results of this search query are displayed. Right now, only the ['SchoolName'] is being displayed. Not sure how to add the extra columns I need.

    As seen here...

    echo "<p><h4>".$results['SchoolName']."</h4>".$results['text']."</p>";
                    // posts results gotten from database(title and text) you can also show id ($results['id'])
    If you can also hint my way to some decent CSS for the display purposes, that would be great.

    Here's the full script...
        mysql_connect("localhost", "username", "password") or die("Error connecting to database: ".mysql_error());
            localhost - it's location of the mysql server
            username - db username
            password - password assigned to username
            if connection fails it will stop loading the page and display an error
        mysql_select_db("jpcsolut_IllegitimateHS") or die(mysql_error());
        /* jpcsolut_IllegitimateHS is the name of database we've created */
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <title>Illegitimate HS Search Results</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="style.css"/>
        $query = $_GET['query']; 
        // gets value sent over search form
        $min_length = 2;
        // 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 IllegitimateHighSchools
                WHERE (`SchoolName` LIKE '%".$query."%')") or die(mysql_error());
            // * means that it selects all fields, you can also write: `id`, `title`, `text`
            // IllegitimateHighSchools is the name of our table
            // '%$query%' is what we're looking for, % means anything
            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><h4>".$results['SchoolName']."</h4>".$results['text']."</p>";
                    // posts results gotten from database(title and text) you can also show id ($results['id'])
            else{ // if there is no matching rows do following
                echo "This is great news! That school is NOT on our Illegitimate High School List...";
        else{ // if query length is less than minimum
            echo "Minimum length is ".$min_length;

  2. #2
    Join Date
    Aug 2012
    I would say that this is causing your problem as you can't nest heading tags inside paragraph tags
    PHP Code:
    echo "<p><h4>".$results['SchoolName']."</h4>".$results['text']."</p>" 
    Change it to below and see what happens
    PHP Code:
    echo "<p>".$results['SchoolName']." - ".$results['text']."</p>" 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center