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

  • SEARCH
  • Home
  • 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 7443701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:22:24+00:00 2026-05-29T11:22:24+00:00

I tried to read out data from a specific date from a MySQL database.

  • 0

I tried to read out data from a specific date from a MySQL database.
What I wanted is for PHP to get all of the data from the database within a specific date that I entered, but it seems that the script just got only the first row of data and left out the rest.

Can you please help me with code to achieve this.

<?php
    if(isset($_REQUEST['query']))
    {
        $searchQuery = $_POST['data-search'];

        //connceting to db
        $con = mysql_connect($_SERVER['SERVER_NAME'],'root','');
        if(!$con)
        {
            die("Error connecting: ".mysql_error());
            exit;
        }
        //selecting db
        $dbSelect = mysql_select_db("directory",$con);
        $query = "SELECT * FROM websites WHERE Date LIKE '$searchQuery'";
        //executing query
        $result = mysql_query($query,$con);
        if(!$result)
        {
            die("Could not connect: ".mysql_error());
        }
        while($row = mysql_fetch_array($result))
        {
            $searchOutput = "<html><body><table border=1><tr><td>Website Title</td><td>Website URL</td><td>About Website Content</td></tr>
                                <tr><td>".$row['Title']."</td><td>".$row['URL']."</td><td>".$row['Content']."</td></tr></table>";
        }
        $searchSuccess = "<p>Your Search was successful</p</body></html>";
        mysql_close($con);
        echo $searchOutput;
        echo $searchSuccess;

    }
    else{
        echo "Invalid";
    }

?>
  • 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-29T11:22:25+00:00Added an answer on May 29, 2026 at 11:22 am

    In your script you replace $searchOutput every time it passes through the loop.

    Change:

    while($row = mysql_fetch_array($result))
        {
            $searchOutput = "<html><body><table border=1><tr><td>Website Title</td><td>Website URL</td><td>About Website Content</td></tr>
                                <tr><td>".$row['Title']."</td><td>".$row['URL']."</td><td>".$row['Content']."</td></tr></table>";
        }
    

    to:

    $searchOutput = "<html><body><table border=1><tr><td>Website Title</td><td>Website URL</td><td>About Website Content</td></tr>";
    
    while($row = mysql_fetch_array($result))
        {
            $searchOutput .= "<tr><td>".$row['Title']."</td><td>".$row['URL']."</td><td>".$row['Content']."</td></tr>";
        }
    
    $searchOutput .= "</table>";
    

    BTW you should consider refactoring your code so that all the templating/formatting stuff is separated from the database logic stuff. It will make it easier to read and maintain in the long run.

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

Sidebar

Related Questions

I tried to read data from my database to find out is I inserted
I have a PHP script that selects some data from mysql and throw it
HI all, When I tried to read the record of all peoples from the
I want to use JPA (eclipselink) to get data from my database. The database
I am new to file handling, when I tried to read data from keypad
I just read Emacs :TODO indicator at left side , and tried it out.
I have read the following properties from AD, TerminalServicesProfilePath TerminalServicesHomeDirectory TerminalServicesHomeDrive I've tried DirectoryEntry
my C# application reads data from special USB device. The data are read as
TLDR; How do I read data from a table using Entity Framework, when the
I am performing a scattered read of 8-bit data from a file (De-Interleaving a

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.