Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:11:05+00:00 2026-05-30T08:11:05+00:00

Same problem was discussed earlier and I also knew that nothing, not also a

  • 0

Same problem was discussed earlier and I also knew that nothing, not also a whitespace can be sent to browser before if we’ve expected call to header function. I am doing wrong here, I am printing HTML div tags before, so solution is to just follow a basic strategy so as everything would work that I wanted to be! FYI, I can do this with AJAX (Using jQuery) by just returning JSON encoded output from called php script as a response (it may be result part or error I am displaying in below code)–everything would work by using AJAX. But as it’s a search page, I am availing facility to user like url rewriting for search_query in the URL so there will be no need to fill the form if user wants–Hence using GET method. Below is my code I’m achieving this:

<div class="two-third">

                        <?php if($_GET['err'] == "no_results_found") {
                            echo "<p class='error-box'>No results found for your query. Please search using different specific keywords.</p>";
                        } ?>

                        <form method="GET" action="<?php echo BASE_URL; ?>/content.php" id="search_content_form">
                                    <fieldset>
                                        <div>
                                            <label>Search this site: </label>
                                            <input type="text" title="Enter your query" class="form-poshytip" id="search_query" name="search_query" value="<?php echo $search_query; ?>">
                                        </div>
                                        <p><input type="submit" id="search_content_submit_button" value="Search Content"></p>
                                        </fieldset>
                                </form>

                        <?php if(isset($search_query)) {

                        $query = "SELECT * FROM (

                                    (SELECT 'event' AS content_type, event_id AS content_id, event_title AS content_title, publishing_time AS content_publishing_time FROM event WHERE event_title LIKE '%".$search_query."%' OR content LIKE '%".$search_query."%') 

                                    UNION 

                                    (SELECT 'article' AS content_type, article_id AS content_id, article_title AS content_title, publishing_time AS content_publishing_time FROM article WHERE article_title LIKE '%".$search_query."%' OR content LIKE '%".$search_query."%')

                                    ) content_result 

                                    ORDER BY content_result.content_publishing_time DESC 
                                    LIMIT 500
                                ";
                        $result = mysql_query($query);
                        if(!$result) {
                            header("location:".BASE_URL."/content.php");
                        }
                        if(mysql_num_rows($result) == 0) {
                            header("location:".BASE_URL."/content.php?err=no_results_found");
                        }

                        $i = 0;
                        echo "<div id='search_content_results' class='list'>";
                        echo "Found <strong>".mysql_num_rows($result)."</strong> result(s) for search query: \"<strong>".$search_query."</strong>\"";
                        while($row = mysql_fetch_assoc($result)) {
                            // extract all needed varaibles from $row
                            $content_type = $row['content_type'];
                            $content_id = $row['content_id'];
                            $content_title = $row['content_title'];
                            $content_publishing_time = $row['content_publishing_time'];

                            echo "
                                    <ul>
                                        <li><a href='".BASE_URL."/".$content_type."s.php?".$content_type."_id=".$content_id."'>".($i+1).") <strong>".$content_title."</strong> <span style='font-size: 12px; text-decoration: italic;'>(Published On: ".date('M jS Y', strtotime($content_publishing_time)).")</span></a></li>
                                    </ul>
                            ";
                            $i++;
                        }
                        echo "</div>";
                    }

                    ?>


                    </div>
                    <!-- ENDS two-third -->

FYI: $search_query above is a alias of $_GET[‘search_query’]


Everything in above code works except the if blocks where header() is called. I know the reason, as mentioned earlier. Just help me to check everything at top of page which is in IF blocks I’ve been using, then display search form and then echoed output of search query when num_rows are more than 0 or display error (as in in above code) if num_rows of result of MySQL query is 0. Sorry for my poor language (also, not proper formating too) as I’m in a hurry. 😉


EDIT:
Logic is simple:

  • $_GET[‘search_query’] then execute query and check for num_rows
    • num_rows==0 then send redirect to same page with “?err=example_error_message” and display that error message above form and do not print the results output at the same time
    • num_rows>0 then print $row values (let us say, final output) as I’ve done in above code
  • No $_GET[‘search_query’] then only search form

So please help me to achieve these.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:11:06+00:00Added an answer on May 30, 2026 at 8:11 am

    I’m not entirely sure whether I understand your question, but I’ll give it a go anyway.

    When you are working with PHP’s header functions, you must indeed make sure not to write any output before the call to the header function.

    Sometimes this is however difficult to do. In order to solve this, you need to use Output buffering. Put ob_start() (docs) as the very first line of your script, and ob_end_flush (docs) or ob_end_clean (docs) as the last line (or after the use of the header functions). This effectively buffers all output, which allows you to call the header functions before any output is actually echoed (as all output is buffered until you call ob_end_flush or ob_end_clean).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have essentially the same problem discussed here: http://khason.net/blog/dependency-property-getters-and-setters-in-multithreaded-environment/ public static readonly DependencyProperty MyPropertyProperty
I have the same problem as described in the posts listed below. That is,
I am having the same problem as this post but the answer does not
I'm having a problem similar to but not quite the same as one I've
I'm experiencing the same problem in this previous stackoverflow.com post . Specifically, I seem
I have the same problem as described in ( Last record of Join table
I have basically the same problem outlined in this question, however I am using
Does anyone have the same problem as I do? ... I've upgraded to the
I have the same problem as in the following post . So I am
I always run into the same problem when creating web pages. When I add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.