Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Location
    dublin
    Posts
    5

    Unanswered: please help me with next button and previous

    hi i need help with a next button and previous button, im using php to connect to my mysql database..my table appears and the next button works..but then when it reaches the end of the file,the table appears blank..Does anybody know how to do this?? My project is an online video shop, so when the user log's in they can click next to view the next video and previous video etc...anyway heres my code..it's pretty crap but im a beginner!! So if anybody can help me with a next buttton and previous button to move through my database,,it would be greatly appreciated as i'm presenting this assignment tomorrow to my lecturer!!

  2. #2
    Join Date
    Mar 2004
    Location
    dublin
    Posts
    5

    sorry heres the code

    heres my code

    <?php
    session_start();
    ?>

    <?php
    $max_cols = 1;
    if(!$start)
    $start = 0;

    echo '<body bgcolor="#000066">';
    $db = mysql_connect("mysql.internal", "db", "Wplij23d")
    or die("Couldn't connect to the database.");
    mysql_select_db("envy")
    or die("Couldn't select the database");
    $result = mysql_query("SELECT * FROM GameTitle LIMIT $start,$max_cols",$db);
    //
    $num=mysql_num_rows($result);
    $myrow = mysql_fetch_array($result);

    if ($num!=0)
    {
    echo"<table width=\"95%\" border=\"1\" bordercolor= \"#990000\" height=\"245\">";
    echo"<tr>";
    // echo"<td rowspan=\"6\" width=\"30%\">";
    echo"<div align=\"left\">";
    echo"<font color=\"#FFFFFF\">";



    echo"<td width=\"21%\">";
    echo"<font color=\"#FFFFFF\">";
    echo"Title";
    echo"</td>";

    echo"<td width=\"49%\">";
    echo"<font color=\"#FFFFFF\">";
    //echo"<td><FONT COLOR = \"#FFFFFF\" </font>Title : </td><td><input type = \"text\" name = \"title\" size = 50 maxlength = 75 value = \"$myrow[3]\"></td>";

    printf("%s",$myrow["gameName"]);
    echo"</td>";
    echo"</tr>";

    echo"<tr>";
    echo"<td width=\"21%\">";
    echo"<font color=\"#FFFFFF\">";
    echo"Rating";
    echo"</td>";

    echo"<td width=\"49%\">";
    echo"<font color=\"#FFFFFF\">";
    //echo"<td><FONT COLOR = \"#FFFFFF\" </font>Name : </td><td><input type = \"text\" name = \"title\" size = 50 maxlength = 75 value = \"$myrow[2]\"></td>";
    printf("%s",$myrow["gameRating"]);
    echo"</td>";
    echo"</tr>";


    echo"<tr>";
    echo"<td width=\"21%\">";
    echo"<font color=\"#FFFFFF\">";
    echo"Genre";
    echo"</td>";

    echo"<td width=\"49%\">";
    echo"<font color=\"#FFFFFF\">";
    //echo"<td><FONT COLOR = \"#FFFFFF\" </font>Name : </td><td><input type = \"text\" name = \"title\" size = 50 maxlength = 75 value = \"$myrow[3]\"></td>";
    printf("%s",$myrow["gameGenre"]);
    echo"</td>";
    echo"</tr>";
    echo"</table>";

    echo"<table>";
    echo"<td>";
    echo"<font color=\"#FFFFFF\">";

    $start = $start + $max_cols;
    print("<FORM action=\"match2.php\" method=\"post\">\n");
    print("<INPUT TYPE=\"hidden\" name=\"start\" size = 1 value=$start>\n");
    print("<INPUT TYPE=\"submit\" value=\">>Next >>\">\n");
    print("</FORM>\n");

    $start = $start - $max_cols;
    print("<FORM action=\"match2.php\" method=\"post\">\n");
    print("<INPUT TYPE=\"hidden\" name=\"start\" size = 1 value=$start>\n");
    print("<INPUT TYPE=\"submit\" value=\"<<Previous <<\">\n");
    print("</FORM>\n");


    print("<FORM action=\"rent2.php\" method=\"post\">\n");
    echo"<input type = \"hidden\" name = \"gamestitle\" size = 1 maxlength = 20 value = \"$myrow[1]\"></td>";
    echo"<input type = \"hidden\" name = \"price\" size = 1 maxlength = 20 value = \"5.00\"></td>";
    print("<INPUT TYPE=\"submit\" value=\" Rent \">\n");
    print("</FORM>\n");
    echo"</table>";
    echo"</td>";
    echo"</tr>";



    }

    ?>

  3. #3
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    wouldnt that mysql_num_rows function not work because you are trying to count how many rows you have already selected in the database after using LIMIT.
    Mr. Lars

  4. #4
    Join Date
    Mar 2004
    Location
    dublin
    Posts
    5
    Originally posted by lslars31
    wouldnt that mysql_num_rows function not work because you are trying to count how many rows you have already selected in the database after using LIMIT.
    i tried commenting out that piece of code but, when i went to the games table...nothing appeared in my table .... so i reckon i need it to display the table...

  5. #5
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    what i am saying is, you need to connect to the "WHOLE" table to count all of the rows, instead of connecting to a table using LIMIT. for example: with SELECT * FROM table LIMIT 0,10 using the num_rows function you would only get "10" if you select the whole table like this: SELECT * FROM table, the mysql_num_rows function would output every row in the table, which is what you want to create your page output. Am I right?
    Mr. Lars

  6. #6
    Join Date
    Mar 2004
    Location
    dublin
    Posts
    5
    Originally posted by lslars31
    what i am saying is, you need to connect to the "WHOLE" table to count all of the rows, instead of connecting to a table using LIMIT. for example: with SELECT * FROM table LIMIT 0,10 using the num_rows function you would only get "10" if you select the whole table like this: SELECT * FROM table, the mysql_num_rows function would output every row in the table, which is what you want to create your page output. Am I right?
    yep ur right!!

Posting Permissions

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