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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:44:12+00:00 2026-06-03T10:44:12+00:00

i got a little problem with searching my database and outputting the data. This

  • 0

i got a little problem with searching my database and outputting the data.

This is my template. Don’t mind the $page->_(). this is because of my framework. just think of phps echo

<?php
$movies = array();
if( isset($_POST['searchtext']) && isset($_POST['ajax']) && $_POST['ajax']==1 )
    $movies = Movie::getByTitle( $_POST['searchtext'] );
$list = '<ul id="results">'; 
if( isset( $movies ) && $movies!=null )
    foreach($movies as $movie)
         $list.= '<li>'.$movie->getTitle().'</li>';
else if( isset($_POST['ajax']) && $_POST['ajax']==1 )
    $list.='<li>No Results!</li>';
$list.= '</ul>';

if(isset($_POST['ajax']) && $_POST['ajax']==1){
    $json = array(
        'success' => true,
        'html' => $list
    );
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Expires: 0');
    header('Content-type: text/json');
    echo json_encode($json);
    die();
}
$page->_(
'<section class="dialog-fixed small">',
    '<form id="search-form" method="post" action="#home">',
        '<fieldset>',
            '<input type="text" name="searchtext" />',
            '<input type="submit" name="moviesubmit" value="Search"/>',
        '</fieldset>',
    '</form>'
);
$page->_($list);
$page->_('</section>');
?>

Movie::getByTitle just does a SELECT * FROM movies WHERE title LIKE '%".$title."%' LIMIT 30" query, creates for each result an Movie Object and return an array with the objects

My jQuery AJAX Request works like this:

var f0 = $('#search-form');
if( f0.length>0 ) {
    f0.each(function(){
        var f = $(this);
        $(this).submit(function(ev){
            ev.preventDefault();
            $.ajax({
                type: 'post',
                url: BASEURL+f.attr('action'),
                data: f.serialize()+'&ajax=1',
                dataType: 'json',
                success: function(data) {
                    if(data.success){
                        $('#results').replaceWith(data.html);
                    }
                },
                error: function(xhr,txt,err) {
                    alert(txt+' ('+err+')');
                }
            });
        });
    });
}

Now..the Database table i query has about 1.000.000 rows (movies)
It works very well if i search for “Forrest Gump” for example…But if i search for something with fewer Characters lets say “One” it doesnt return anything. I tried searching my Database inside of phpmyadmin for “One” and it returned about 15.000 results…okay i thought this could be too many for my script to handle so i put a LIMIT 30 at the end of my database query as you can see..
doesnt work either. i dont get anything in return after searching for “One” not even a “No Result” as it should (actually it shouldnt but you know what i mean). My script just stops working.
And if i searched for something like “One” i can’t search anything after this. Not even “Forrest Gump” gives me any results.
Really cant figure out where the problem is. My Firebug doesnt help me 😉

Any hints?

EDIT:
Ok i found out where my problem was. json_encode($json) didn’t work. i didnt figure out the reason yet. This solution works:
script.js:

$.ajax({
                type: 'post',
                url: BASEURL+f.attr('action'),
                data: f.serialize()+'&ajax=1',
                dataType: 'text',
                success: function(data) {
                    if(data!=''){
                        $('#results').replaceWith(data);
                    }
                },
                error: function(xhr,txt,err) {
                    alert(txt+' ('+err+')');
                }
            });

php template:

if(isset($_POST['ajax']) && $_POST['ajax']==1){
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: 0');
header('Content-type: text/html');
echo utf8_encode($list);
die();
}
  • 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-03T10:44:16+00:00Added an answer on June 3, 2026 at 10:44 am

    Ok..found the problem. Some of the Strings in my database weren’t correctly UTF-8…json_encode() had trouble with this so in my php template i had to change $list.= '<li>'.$movie->getTitle().'</li>'; to $list.= '<li>'.utf8_encode($movie->getTitle()).'</li>';

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

Sidebar

Related Questions

I got a little problem with my SQLite database in my app. My goal
I've got a little problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped
I've got a little problem: I don't know whether it is possible to select
I've got this little problem. When I have a string 3 568 030 and
i`ve got a little problem with LINQ. I read out some information via XML-RPC.
I got a little problem. Sometimes, when I try to call the following code,
I got a little problem, I got a code, that reads all pixels and
I got a little problem, it seems simple (personally I think it is), but
I've got a little problem that's slightly frustrating. Is it possible to set a
I've got a little problem using WPF Dispatcher Timer. On each timer tick my

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.