+ Reply to Thread
Results 1 to 5 of 5

Thread: php

  1. #1
    jagosof is offline x10Hosting Member jagosof is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    4

    php

    I am writing a search form for my site and I cant seem to get it to work properly

    I seen it to search the name or age or both and bring be back the results if say there are more than 5 then to bring them back on diffrent pages. this is what I have so far it works but I want to also have a submit all button insted of say just submits after each query.
    please help

    Terry

    <form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
    </font></p><p><font size="2" color="#ffffff">First Name: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    <form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
    </font></p><p><font size="2" color="#ffffff">Age: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    </form>
    <form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
    </font></p><p><font size="2" color="#ffffff">Birth Year: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    </form>
    <form action="http://jagosofcornwall.co.cc/genes/ww1.php" method="post">
    </font></p><p><font size="2" color="#ffffff">Parish: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>



    <?php
    include "mysql.class.php";
    // Create a new mysql object
    $mysqldb = new mysql("localhost","dbuser","password","db");
    // Connect to the database server and select a database

    $mysqldb->connect();
    $mysqldb->select();
    $pagesize = 2;
    $term=$_POST['term'];
    $recordstart = (isset($_GET['recordstart'])) ? $_GET['recordstart'] : 0;
    $mysqldb->query("select * from ww1 where Name like '%$term%' LIMIT $recordstart,$pagesize");
    // Output the result set
    $actions = '<a href="http://jagosofcornwall.com/ww1/idVALUE.htm">View Detailed</a>';
    echo $mysqldb->getResultAsTable($actions);
    $mysqldb->query("select count(id) as count FROM ww1");
    $row = $mysqldb->fetchObject();
    $totalrows = $row->count;
    // Create the 'previous' link
    if ($recordstart > 0) {
    $prev = $recordstart - $pagesize;
    $url = $_SERVER['PHP_SELF']."?recordstart=$prev";
    echo "<a href=\"$url\">Previous Page</a> ";
    }
    // Create the 'next' link
    if ($totalrows > ($recordstart + $pagesize)) {
    $next = $recordstart + $pagesize;
    $url = $_SERVER['PHP_SELF']."?recordstart=$next";
    echo "<a href=\"$url\">Next Page</a>";
    }
    $totalpages= ceil($totalrows / $pagesize);
    $currentpage = ($recordstart / $pagesize ) + 1;
    function pageLinks($totalpages, $currentpage, $pagesize,$parameter) {
    // Start at page one
    $page = 1;
    // Start at record zero
    $recordstart = 0;
    // Initialize $pageLinks
    $pageLinks = "";
    while ($page <= $totalpages) {
    // Link the page if it isn't the current one
    if ($page != $currentpage) {
    $pageLinks .= "<a href=\"".$_SERVER['PHP_SELF']."
    ?$parameter=$recordstart\">$page</a> ";
    // If the current page, just list the number
    } else {
    $pageLinks .= "$page ";
    }
    // Move to the next record delimiter
    $recordstart += $pagesize;
    $page++;
    }
    return $pageLinks;
    }

    echo "<p>Pages: ".
    pageLinks($totalpages,$currentpage,$pagesize,"reco rdstart").
    "</p>";

    ?>

    </body>
    </html>

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: php

    If I understand you correctly, you want the user to press 'submit' once and then it will query the database once, but you want the results to be displayed 5 at a time?

    I think what you have now, with multiple queries, is the best way to go, though you can use the php serialize function to save every row and then use sessions, cookies, etc to pass the results along. If you just want to hide the submit button, you can use javascript:
    Code:
    SCRIPT language="JavaScript">
    function submitform()
    {
      document.myform.submit(); //myform is the name of your form
    }
    </SCRIPT>
    and you can use anything you want to submit the form:
    Code:
    <a href="javascript:submitform()">next</a>
    I hope this is what you're asking
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    jagosof is offline x10Hosting Member jagosof is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    4

    Re: php

    Thank you for your reply, I have put that into play but its not quite want I want. I would like what you suggested too where someone can either submit one query with say name or type in name age address and then submit. I cant work out how to use just one submit button.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: php

    Better would be to use a single form and have your form handler construct the WHERE clause based on which input fields are set.

    And don't forget to sanitize user input with (e.g.) mysql_real_escape_string or the filter functions to prevent SQL injection.

  5. #5
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: php

    @jagosof
    try to use the CODE or the PHP tags next time
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers