Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP info instead of echo store to file?

    The code below is kept in a file called search.php I call this file with an include to the index page performing a search function. The issue is the search is in the top right corner and the results end up appearing in the top right corner instead of in the main text part of the page.I use and include to make the search work on my main index page. The problem is when someone searches it replaces the search box with the results in the same section when i want it to post the results in the main section... your help is appareciated.



    Code:
    // Get the absolute path for including files
    $path = __FILE__;
    $path = str_replace('search.php', '', $path);
    
    include_once($path . 'settings.php');
    
    echo '<form action="' , $_SERVER['PHP_SELF'] , '?action=search" method="post">
    <table border=0>
    <td valign=top>Search For a Specific Magazine:</td><td valign=top><input id="keyword" name="keyword" size="32" type="text"><br>
    <td valign=top><input type=submit value="Search" name="ok"></td>
    </table>
    </form>';
    
    if ($_GET['action'] == 'search')
    {
    $search = addslashes($_POST['keyword']); // THIS FUNCTION IS EXTREMEMLY IMPORTANT!
    // How would you like it if a user tried to search with a mysql_query command
    // and deleted you'r entire db?
    // This funtion says NO to things like that :P
    // All searches with characters like this will be edited: ", ', \, NULL,
    // And added slashes.  nice function!
    
    $connection = mysql_connect ($db_server, $db_user, $db_passwd) or die("Could not connect to db");
    $database = mysql_select_db($db_name, $connection);
    $result = mysql_query('SELECT * FROM ' . $db_prefix . 'news WHERE maintext LIKE "%' . $search . '%" OR titletext LIKE "%' . $search . '%"', $connection);
    
    if($search == '%') { // We do not want the user to search for % (it would output everything)
    echo 'Please type a valid search keyword!';
    }
    elseif($search == '') { // We do not want the user to search for nothing
    echo 'Please type a valid search keyword!';
    }
    else
    {
    echo '<u>Result of your search (<i>' , $search , '</i>):<br><br></u>';
    $i = 1; 
    While ($row = mysql_fetch_assoc($result)) {
    echo $i ;
    echo ".";
    echo "&nbsp;";
    echo '<a href="news-' . $row['id'] . '.html">' , stripslashes($row['subject']) , '</a><br><br>';
    $i++;
    
    
    }

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You would have to rearrange your index file script so that when the search is performed the content it outputted in the main table and not where the search box is included.

    You could do this by seperating the search form and the results into seperate scripts.

    or you could use Ajax to call the form and populate an element in the page
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by degsy

    You could do this by seperating the search form and the results into seperate scripts.

    [/url]
    Thats what i want to do but don't know how. Thats what i was meaning by instead of echoing the results how do i store them to a file? then call that file to main table.

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If it's for temporary storage then I wouldn't bother. Just put the results into a session var or something.

    If you want to write to file then use fopen, fputs etc.
    http://uk2.php.net/manual/en/function.fwrite.php

  • #5
    New to the CF scene
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    unfortunately my host dreamhost does not allow fopens....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •