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 7879849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:59:50+00:00 2026-06-03T03:59:50+00:00

The query I have below will only show me one result even if there

  • 0

The query I have below will only show me one result even if there are multiple matching entries (completely or partially matching). How do I fix it so it will return all matching entries:

//$allowed is a variable from database.

$sql = "SELECT `users`.`full_name`, `taglines`.`name`, `users`.`user_id` FROM 
`users`  LEFT JOIN `taglines` ON `users`.`user_id` = `taglines`.`person_id`
 WHERE ( `users`.`user_settings` = '$allowed' ) and ( `users`.`full_name` 
 LIKE '%$q%' ) LIMIT $startrow, 15";

$result = mysql_query($sql);

$query = mysql_query($sql) or die ("Error: ".mysql_error());

$num_rows1 = mysql_num_rows($result);

if ($result == "")
{
    echo "";
}
echo "";


$rows = mysql_num_rows($result);

if($rows == 0)
{

}
elseif($rows > 0)
{
    while($row = mysql_fetch_array($query))
    {
        $person = htmlspecialchars($row['full_name']);
    }
}
}  

print $person;
  • 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-06-03T03:59:51+00:00Added an answer on June 3, 2026 at 3:59 am

    Because your overwriting $person on each iteration.

    Hold it in a $person[] array if your expecting more then one. Then loop through it with a foreach loop when you intend to output.

    Not related but your also querying twice, you only need 1 $result = mysql_query($sql);

    Update (Simple Outputting Example):

    <?php 
    $person=array();
    
    while($row = mysql_fetch_array($query)){
     $person[] = array('full_name'=>$row['full_name'],
                       'email'=>$row['email'],
                       'somthing_else1'=>$row['some_other_column']);
    }
    
    //Then when you want to output:
    foreach($person as $value){
        echo '<p>Name:'.htmlentities($value['full_name']).'</p>';
        echo '<p>Eamil:'.htmlentities($value['email']).'</p>';
        echo '<p>FooBar:'.htmlentities($value['somthing_else1']).'</p>';
    }
    ?>
    

    Or an alternative way to is to build your output within the loop using concatenation.

    <?php 
    $person='';
    while($row = mysql_fetch_array($query)){
     $person .= '<p>Name:'.$row['full_name'].'</p>';
     $person .= '<p>Email:'.$row['email'].'</p>';
    }
    
    echo $person;
    ?>
    

    Or just echo it.

    <?php 
    while($row = mysql_fetch_array($query)){
     echo '<p>Name:'.$row['full_name'].'</p>';
     echo '<p>Email:'.$row['email'].'</p>';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that returns a result set similar to the one below:
I have below query I am trying to show message 'No SubSource for this
The sql injection will work only when my query looks like below sample SELECT
I have below a working query that needs to be simplified. The reason is
We have the query below. Using a LEFT OUTER join takes 9 seconds to
I have the query below that when run it says that 325 rows were
I'm using Sql-Server, and I have the below query which returns all columns that
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
I have an SQL query (below) that essentially takes a student from tbStudents, and
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action

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.