54 users online (0 members and 54 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 2
  2. Getting crazy with image uploading    Forum: PHP Forum
    Replies: 1
  3. a:hover driving me crazy    Forum: CSS Forum
    Replies: 7
  1. #1
    DarthSidious666's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Location
    ???
    Posts
    4

    Unhappy My PHP is driving me CRAZY

    Hi everyone, I really, need some help on this PHP I'm writing. But first, an explaination is in order I think

    I am trying to write a database search engine using php and mysql, the search is fine until I try to turn the page.

    Here's the code:

    PHP Code:
    <?php
        
    $rpp;        //Records Per Page
        
    $cps;        //Current Page Starting row number
        
    $lps;        //Last Page Starting row number
        
    $a;        //will be used to print the starting row number that is shown in the page
        
    $b;         //will be used to print the ending row number that is shown in the page
        
        /////////////////////////////////////////////////////////////////////////////////
        //Database connection
        /////////////////////////////////////////////////////////////////////////////////
        
    $odbc mysql_connect("localhost""""") or die("Cannot connect to SQL server.");
        @
    mysql_select_db("cars") or die( "Unable to select database");

        
    /////////////////////////////////////////////////////////////////////////////////
        //Following IF Statement is used to make sure when the page is loaded for the
        //first time, Current Page's Starting row number is 0, i.e. 1st row from the
        //table is being printed. It will change as the user will click on next.
        /////////////////////////////////////////////////////////////////////////////////   
        
    if(empty($_GET["cps"]))
        {
            
    $cps "0";
        }
        else
        {
            
    $cps $_GET["cps"];
        }
        
    /////////////////////////////////////////////////////////////////////////////////

        
    $a $cps 1;

        
    $rpp "8";

        
    $lps $cps $rpp//Calculating the starting row number for previous page

        /////////////////////////////////////////////////////////////////////////////////
        //Following IF Statement is used to make sure whether a link to Previous page is
        //needed or not. If the user is viewing the first set of data then the link will
        //be disabled, if on the next set then it will carry the $lps in its link and
        //enable the link
        /////////////////////////////////////////////////////////////////////////////////
        
    if ($cps <> 0)
        {
            
    $prv =  "<a href='paging.php?cps=$lps'>Previous</a>";
        }
        else   
        {
            
    $prv =  "<font color='cccccc'>Previous</font>";
        }
        
    /////////////////////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////////////////////
        //Following SQL Statement uses SQL_CALC_FOUND_ROWS function to calculate total
        //number of rows found by the query excluding the limit function added at the
        //end of the SQL statement. This is followed by second query with FOUND_ROWS()
        //function which actually gives out the number of rows found.
        /////////////////////////////////////////////////////////////////////////////////
        
    $searchType $_REQUEST['searchType'];
        
    $searchTerm $_REQUEST['searchTerm'];
        
        
    $q="SELECT sql_calc_found_rows * FROM cars WHERE $searchType LIKE '%$searchTerm%' LIMIT $cps$rpp";
        
    $rs=mysql_query($q$odbc) or die(mysql_error());
        
    $nr mysql_num_rows($rs); //Number of rows found with LIMIT in action

        
    $q0="SELECT FOUND_ROWS()";
        
    $rs0=mysql_query($q0$odbc) or die(mysql_error());
        
    $row0=mysql_fetch_array($rs0);
        
    $nr0 $row0["FOUND_ROWS()"]; //Number of rows found without LIMIT in action
        
        /////////////////////////////////////////////////////////////////////////////////
        //Following IF Statement is used to determine whether the user has reached the
        //last page of the records. For example, if we have 27 rows to print and we show
        //10 rows per page, then on the third and the last page it will show seven rows
        //and will say at the top that SHOWING RECORDS FROM 21 to 27. If the following
        //validator is not used then it shows SHOWING RECORDS FROM 21 to 30.
        /////////////////////////////////////////////////////////////////////////////////   
        
    if (($nr0 8) || ($nr 8))
        {
            
    $b $nr0;
        }
        else
        {
            
    $b = ($cps) + $rpp;
        }
        
    /////////////////////////////////////////////////////////////////////////////////

        
    ?>
    <br>
    <table border="0" cellpadding="4" cellspacing="1" width="20%" align="center">
      <tr><td align='left' colspan="2"><b><font face="verdana" size=1 color="#9999CC"><? echo "$nr0 Records Found"?></font></b></td></tr>
      <tr><td align='right' colspan="2"><b><font face="verdana" size=1 color="#9999CC"><? echo "Showing Records from $a to $b"?></font></b></td></tr>
      <tr><td bgcolor="#000080" align='Center'><b><font face="verdana" color="#FFFFFF">Index</font></b></td>
      <td bgcolor="#000080" align='Center'><b><font face="verdana" color="#FFFFFF">Make</font></b></td>
      <td bgcolor="#000080" align='Center'><b><font face="verdana" color="#FFFFFF">Model</font></b></td>
    </tr>
        <?
        
    echo $q;
        
        while (
    $row mysql_fetch_array($rs))
        {
            
    /////////////////////////////////////////////////////////////////////////////////
            //This is used to show the serial number on the page as well as to count it up
            //so that we can get the next page's starting row number when it exits the while
            //loop after fullfilling the above SQL criteria.
            /////////////////////////////////////////////////////////////////////////////////
            
    $cps $cps +1;
            
            echo 
    "<tr>
                    <td align='center'><font face=verdana>
    $cps</font></td>
                    <td align='center'><font fave=verdana>"
    .$row['make']."</font></td>
                    <td align='center'><font fave=verdana>"
    .$row['model']."</font></td>
                </tr>"

        }
       
        echo 
    "<tr><td align='right' colspan=2>$prv";

        
    /////////////////////////////////////////////////////////////////////////////////
        //Following IF Statement is used to determine whether the Next link will be
        //enabled or disabled. If the user has reached the last page of the record, then
        //the Next link will be disabled.
        /////////////////////////////////////////////////////////////////////////////////
        
        
    if ($cps == $nr0)
        {     
            echo 
    "  |  <font color='CCCCCC'>Next</font>";
        }
        else
        {
            if (
    $nr0 8)
            {
                echo 
    "  |  <a href='$self?searchType=$searchType?searchTerm=$searchTerm?cps=$cps&lps=$lps'>Next</a>";
            }
        }
        
    /////////////////////////////////////////////////////////////////////////////////
        
    echo "</td></tr></table>";
    ?>
    sorry if its a bit long, I've tried about five versions of this sort of code and NONE of them work, and I don't know why!!!

    I copied it from a site, but most of it I understand already (not bad for someone doing PHP in 1 month )

    <a
    PHP Code:
     echo "<a href='$self?searchType=$searchType?searchTerm=$searchTerm?cps=$cps&lps=$lps'>Next</a>"
    This line seems to be causing the problem but I can't see the solution.

    Thanks in advance for any help you can give this poor n00b.

  2. #2
    DarthSidious666's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Location
    ???
    Posts
    4

    Re: My PHP is driving me CRAZY

    Ooooo... Figured out this part:

    PHP Code:
     echo "  |  <a href='$self?searchType=$searchType&searchTerm=$searchTerm&cps=$cps&lps=$lps'>Next</a>"
    Now need to make the pages go backwards, can anyone help with this?

  3. #3
    DarthSidious666's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Location
    ???
    Posts
    4

    Re: My PHP is driving me CRAZY

    I've cracked it HOORAY!!

    If I need more help I'll reply in this thread.

    Thanks to those who looked.

  4. #4
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: My PHP is driving me CRAZY

    congrats and welcome
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  5. #5
    DarthSidious666's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2008
    Location
    ???
    Posts
    4

    Re: My PHP is driving me CRAZY

    OK I now have a new problem.

    The first textbox requires to be locked and have an auto incrementing number?

    Any ideas how to do this?

    I'm using Firefox so the field really needs to be greyed out and not editable.

    Thanks



Tags for this Thread