Welcome, Guest
  • Author Topic: search not out writing previous results... pull my hair out.  (Read 3719 times)

    brentc73

    • Server what's that
    • *
    • Posts: 16
      • View Profile
    Me again...

    I created a flash/mysql/php photo search engine (tweaking code I found on this site), when I do the initial search the results are perect. If I do another search and there are fewer results than the first search the older result will show along with the new ones... hope this makes sense.

    Example: search "a" and 10 photos show up, then search term "b" and 5 photo show up plus the 5 photos from search "a".

    I need the search to only show the current search results... and I cannot figure it out.

    Php code
    Code: [Select]

    <?
    //Database Connectivity Variables//
    $host = "website.com";
    $dbuser = "username";
    $dbpass = "passwprd";
    $dbname = "database";
    $table = "Flashsearch";
    //Create a connection to the MySQL Database//
    $connection = @mysql_connect($host,$dbuser,$dbpass) or die("Couldn't Connect.");
    $db = @mysql_select_db($dbname, $connection) or die("Sorry, I could not select the requested Database ");
    //SQL Querys
    $Fname =  $_POST['search'];
    $sql = "SELECT * FROM Flashimages where Fname like '%$Fname%' ORDER BY Fname ASC";
    $result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
    $count = 0;
    while($row=mysql_fetch_array($result)){
    echo "Fname$count=$row[Fname]&Furl$count=$row[Furl]&Fimage$count=$row[Fimage]&";
    $count++;
    }
    echo "count=$count";
    ?>

    and the AS

    Code: [Select]
    stop();
    bar._visible = false;
    search.tabIndex = 1;
    var receiveData_lv:LoadVars = new LoadVars();
    var formValidated:Boolean;
    var errorMessages:Array = new Array();
    receiveData_lv.ref = this;
    receiveData_lv.onLoad = function(success) {
    if (this.count == 0) {
    message0_txt.text = "No entries found";
    trace("No entries found");
    }
    if (this.count>=4) {
    this._parent.mores._visible = false;
    trace("true");
    }
    if (success) {
    for (var i = 0; i<this.count; i++) {
    this.ref["news"+i].text = this["Fname"+i];
    trace(this.ref["news"+i]);
    this.ref["c"+i].loadMovie(this["Fimage"+i]);
    bar._visible = false;
    this.ref["b"+i].uri = this["Furl"+i];
    delete (this["Fname"+i]);
    this.ref["b"+i].onRelease = function() {
    getURL(this.uri, "iframemain");

    };
    }
    }
    };
    submit_btn.onRollOver = function() {
    this.gotoAndStop(2);
    error1.text = "";
    };
    submit_btn.onRollOut = function() {
    this.gotoAndStop(1);

    };
    function sendIt() {
    //this clears the error text field if they have been populate previously
    clearTextFields();
    errorMessages.length = 0;
    //empty the array so next time the submit button is clicked the array is not already populated
    formValidated = checkForm();
    if (formValidated) {
    //the form is valid and so now we can send details to our PHP file
    //populate LoadVars object with the field values
    var sendData_lv:LoadVars = new LoadVars();
    sendData_lv.search = search.text;
    var unnew = new Date().getTime();
    //trace(sendData_lv.email);
    //trace("valid");
    sendData_lv.sendAndLoad("http://www.website.com/New/search_thumbs.php?unnew="+unnew, receiveData_lv, "POST");
    } else {
    //populate textfields with the error messages
    for (var i = 0; i<errorMessages.length; i++) {
    this["message"+i+"_txt"].text = errorMessages[i];
    trace(errorMessages[i]);
    }
    }
    }
    function checkForm():Boolean {
    //check whether the name field is empty
    if (search.text == "") {
    errorMessages.push("Please enter a search term!");
    }
    if (search.text.length<0) {
    errorMessages.push("Search must have a minimum of 1 letters");
    }
    //if at this point the array is empty i.e has length 0, then this in effect means the form has passed all checks                                               
    if (errorMessages.length == 0) {
    return true;
    } else {
    return false;
    }
    }
    function clearTextFields():Void {
    for (var i = 0; i<errorMessages.length; i++) {
    this["message"+i+"_txt"].text = "";
    }
    }
    submit_btn.onRelease = function() {
    sendIt();
    bar._visible = true;
    };
    keyListener = new Object();
    keyListener.onKeyDown = function() {
    if (Key.isDown(Key.ENTER)) {
    sendIt();
    }
    };
    Key.addListener(keyListener);

    Any help would be apprecaited.
    « Last Edit: 10/04/08, 15:08 by brentc73 »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Prior to populate your textfields, you should clean it. Seems you're not creating the textfields on the fly byt just filling with the results. So when the user perform a new search, preiously to send the data to the PHP script, use a loop to clean all your textfields

    Jorge

    brentc73

    • Server what's that
    • *
    • Posts: 16
      • View Profile
    Hi Jorge,

    No sure how to do what you suggested, could you give me hint?


    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Suppose you have ten textfields, currently you're populating like this:


    if (success) {
    	
    	
    for (var 
    0i<this.counti++) {
    	
    	
    	
    this.ref["news"+i].text this["Fname"+i];
                            ....


    Now prior to populate, you should clean. How many textfields do you have? 10? then


    receiveData_lv
    .onLoad = function(success) {
        for (var 
    0i<10i++) {
    	
    	
    	
    this.ref["news"+i].text ""


    And the same for each of your textfields

    Jorge

    brentc73

    • Server what's that
    • *
    • Posts: 16
      • View Profile
    Thank you very much.