SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I have a html form that has 3 dropdown menus, and a submit button. I use GET to send
    the values to the script and print out the result from my database.
    I am also trying to split the results, and only return 15 at a time, I can get the
    first 15 results to show up but when I click on the next to view the next 15 results
    it doesn't display anything in the results table and it gives me the errors
    Warning: Supplied argument is not a valid MySQL result resource in
    /home/obrien02/mysite-www/findit22.php on line 80

    Warning: Supplied argument is not a valid MySQL result resource in
    /home/obrien02/mysite-www/findit22.php on line 91

    line 80 is
    $totalrowsnum = mysql_num_rows($gettotalrows);
    and line 91 is
    while ($result= mysql_fetch_array($query)){


    I have no idea what is wrong with this.
    If it helps I can post the form and script.
    Thanks in advance.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may want to post the code, but I am 99% sure your problem lies with passing the values from the dro pdowns for use in the query to each page not just the first. So when you are creating the links to show the next pages make sure to pass the query data along with it. If that doesn't clear it up then post your code and we can show you exactly what to do.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried to POST also with the same results.
    I'm very new to php so please excuse my lack of knowledge.


    My form code is

    <table BORDER="0" WIDTH="100%" ALIGN="CENTER"><form method="Get" action="findit22.php">

    <td BGCOLOR="#ffffff" VALIGN="top" Width="75%"> face="Arial" size="2">Monthly Price:
    <select name="price" size="1">
    <option value="20">-Under $20-</option>
    <option value="30">-Under $30-</option>
    <option value="50">-Under $50-</option>
    <option value="75">-Under $75-</option>
    <option value="99">-Under $100-</option>
    </select>
    Records:
    <select name="records" size="1">
    <option value="15">- Atleast 15 titles-</option>
    <option value="25">- Atleast 25 titles-</option>
    <option value="50">- Atleast 50 titles-</option>
    <option value="100">- Atleast 100 titles-</option>
    <option value="250">- Atleast 250 titles-</option>
    <option value="500">- Atleast 500 titles-</option>
    </select>
    members:
    <select name="members" size="1">
    <option value="1">-Over 1-</option>
    <option value="15">-Atleast 15-</option>
    <option value="25">-Atleast 25-</option>
    <option value="50">-Atleast 50-</option>
    <option value="100">-Atleast 100-</option>
    </select>
    <center><br>Ok I'm ready/br>
    <input type="submit"
    name="submit" value="Find Me some info!"></center> </form>

    My script code is

    <?


    /*=========================================*/
    /*==Variables used through out the script==*/
    /*=========================================*/
    $server = "localhost"; // Server Name
    $userid = "******"; // Username
    $pass = "*********"; // Password
    $database = "**********"; // Database Name
    $dbtable = "********"; // Table Name
    $recordlimit= 15; // Limit per page

    /*==============================================*/
    /*==Font control for the Next/Prev Naviagation==*/
    /*==============================================*/
    $prevstatus = "Show Previous $recordLimit Results";
    $nextstatus = "Show Next $recordLimit Results";
    $prevlink = "< Previous|";
    $nextlink = "|Next >";
    $fontfamily = "tahoma, helvetica";
    $fontsize = "13px";
    $fontcolor = "#000000";
    $inactivecolor = "#666666"; // Color for when there is no link
    $fontweight = "700";
    $textdecoration = "none";

    /*==========================================*/
    /*==Window Status of individual page links==*/
    /*==========================================*/
    function pagestatus($i){
    echo " Click to View Page $i";
    }

    /*========================================*/
    /*==Make server and database connections==*/
    /*========================================*/
    $con = mysql_connect("$server","$userid","$pass")
    or die ("Connection Error to Server");
    $db = mysql_select_db("$database",$con)
    or die("Connection Error to Database");

    /*==================================================*/
    /*==If thisOffset not set, set to zero==============*/
    /*==================================================*/
    if (!isset($thisoffset) || $thisoffset < 0) $thisoffset=0;
    if ($action==search) $thisoffset = $thisoffset - 1;

    /*==================================================*/
    /*==This is to count the line index of the results==*/
    /*=============if not set, set to zero==============*/
    /*==================================================*/
    if (!isset($lineindex) || $lineindex < 0) $lineindex=0;
    if ($action==search) $lineindex = $lineindex - 1;

    /*========================================*/
    /*==Set Base SQL Statement for the query==*/
    /*========================================*/
    $sql=("select * from $dbtable WHERE price<$price AND records>=$records AND members>=$members order by price asc");
    //$sql.="select * from $dbtable WHERE price<'$price' AND records>='$records' AND members>='$members' $recordlimit= 15";

    /*======================================*/
    /*==Query for the total number of rows==*/
    /*======================================*/
    $gettotalrows = mysql_query($sql, $con);
    $totalrowsnum = mysql_num_rows($gettotalrows);

    /*==========================================*/
    /*==Append the limit and offset to the sql==*/
    /*==========================================*/
    $sql.=" Limit $thisoffset,$recordlimit";

    /*===================================================*/
    /*==Query and fetch array with the limit and offset==*/
    /*===================================================*/
    $query = mysql_query($sql, $con);
    while ($result= mysql_fetch_array($query)){

    /*=================================*/
    /*==Increment the line index by 1==*/
    /*=================================*/
    $lineindex++;

    /*============================================*/
    /*====== Your results layout goes here =======*/
    /*============================================*/

    $id=$result ['id'];
    $name=$result ["name"];
    $url=$result ["url"];
    $price=$result ["price"];
    $records=$result ["records"];
    $members=$result ["members"];
    $description=$result ["description"];
    $rating=$result ["rating"];


    print ($result % 2) ? "<tr bgcolor=\"#FFFFFF\">" : "<tr bgcolor=\"#d3d3d3\">";
    echo "<td align=middle><A HREF=\"$url\" target=\"_blank\">$name</A></td><td align=middle>$price</td>";
    print "<td align=middle>$records</td>";
    print "<td align=middle>$description</td>";
    print "<td align=middle>$rating</td>";
    }

    /*===================================================================*/
    /*==If the number of returned is less than the limit, show nothing===*/
    /*===================================================================*/
    if ($totalrowsnum <= $recordlimit) {
    // less than recordLimit returned.
    } else {

    /*==============================================*/
    /*==If the current offset is not equal to zero==*/
    /*==Show the link. Else (if>0) show just text===*/
    /*==============================================*/
    if ($thisoffset!=0) { $prevoffset = intval($thisoffset-$recordlimit);
    echo "<a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$prevstatus'; return true\""
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisoffset=$prevoffset&lineindex&=$prevoffset\">"
    ."$prevlink</a> ";
    }
    else { echo "<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$prevlink</span> ";
    }

    /*================================================================*/
    /*==Divide total rows by record limit to get the number of pages==*/
    /*================================================================*/
    $totalpages = intval($totalrowsnum/$recordlimit);

    /*===========================================================*/
    /*==If remainder is left from division increment totalPages==*/
    /*===========================================================*/
    if ($totalrowsnum%$recordlimit) $totalpages++;

    /*===========================================================*/
    /*==Using a for() loop, Display links for each page. 1 2 3==*/
    /*===========================================================*/
    for ($i=1;$i<=$totalpages;$i++) {

    /*==================================================================*/
    /*==If the page being viewed is the current page, disable the link==*/
    /*==================================================================*/
    if ((intval($thisoffset/$recordlimit)) == (intval($i-1))) {

    echo " <span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$i</span> ";

    } else {
    /*=======================================================*/
    /*==If not current page, set nextOffset and display link==*/
    /*=======================================================*/
    $nextoffset= intval($recordlimit*($i-1));

    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;' onmouseover=\"window.status='";
    pagestatus($i);
    echo "'; return true\" onmouseout=\"window.status=''\""
    ." href=\"$PHP_SELF?thisoffset=$nextoffset&lineindex=$nextoffset\">$i</a> ";
    }
    }

    /*==========================================================================*/
    /*==If the page is not the last page, set the nextOffset and show the link==*/
    /*==============If the page is the last page disable the link===============*/
    /*==========================================================================*/
    if (!(intval(((intval($thisoffset/$recordlimit))+1))==$totalpages) && $totalpages!=1) {
    $nextoffset = intval($thisoffset+$recordlimit);

    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
    ." text-decoration:$textdecoration;' onmouseover=\"window.status='$nextStatus'; return true\""
    ." onmouseout=\"window.status=''\" href=\"$PHP_SELF?thisoffset=$nextoffset&lineindex=$nextoffset\">$nextlink</a><p>\n";
    }
    else echo " "
    ."<span style='font-family:$fontfamily; font-size:$fontsize; color:$inactivecolor;"
    ." font-weight:$fontweight; text-decoration:$textdecoration;'>$nextlink</span><p>";
    }

    mysql_close($con);
    //End
    ?>

    I really appreciate you guys taking the time to help.

  4. #4
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    instead of this

    /*======================================*/
    /*==Query for the total number of rows==*/
    /*======================================*/
    $gettotalrows = mysql_query($sql, $con);
    $totalrowsnum = mysql_num_rows($gettotalrows);



    try this

    /*======================================*/
    /*==Query for the total number of rows==*/
    /*======================================*/
    $gettotalrows = mysql_query($sql, $con);
    if (!$gettotalrows) {
    echo mysql_error();
    }
    $totalrowsnum = mysql_num_rows($gettotalrows);



    .........
    the above code should echo the complete error...
    i dunno...

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said earlier you need to pass the dropdown vars to each page so change

    Code:
    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor;" 
    ." font-weight:$fontweight; text-decoration:$textdecoration;' onmouseover=\"window.status='"; 
    pagestatus($i); 
    echo "'; return true\" onmouseout=\"window.status=''\"" 
    ." href=\"$PHP_SELF?thisoffset=$nextoffset&lineindex=$nextoffset\">$i</a> ";
    to

    Code:
    echo " <a style='font-family:$fontfamily; font-size:$fontsize; color:$fontcolor;" 
    ." font-weight:$fontweight; text-decoration:$textdecoration;' onmouseover=\"window.status='"; 
    pagestatus($i); 
    echo "'; return true\" onmouseout=\"window.status=''\"" 
    ." href=\"$PHP_SELF?thisoffset=$nextoffset&lineindex=$nextoffset&price=$price&records=$records&members=$members\">$i</a> ";

    See how you need to pass the vars needed in the query to each page in your navigation
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help.

    I made the changes that were suggested, but now when I click on the next button it take the values from the last row of results and doesn't display any results.

    I hope this explains it, In the address bar I get
    http://www.mysite.com/findit22.php?p...e+Some+Info%21

    But when I click on next I get
    http://www.mysite.com/findit22.php?p...200&members=10

    After looking at it I realized it is taking the values from the last row of results returned from the database and not from the holding the values from the form.

    Any suggestions?

    I'm lost.

  7. #7
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    http://www.mysite.com/findit22.php?price=99&records=15&members=1&submit=Find+Me+Some+Info%21 
    PHP Code:
    http://www.mysite.com/findit22.php?price=29&records=200&members=10 
    Sorry it didn't take all the info I typed in the last post.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well since you reassign the values of those vars when displaying the data you are getting new values. You should probably use different var names for your record display than the vars coming from the form to alleviate this.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for being such a pain.
    Could you please give me an example.
    I am really trying to learn, just having a hard time of it.

    Thanks again

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here see how I append a _t to each var name that has the same name as the ones form the form that way they don't get reassigned in the while loop, and now you can safely pass them on in the next links:

    Code:
    while ($result= mysql_fetch_array($query)){ 
    
    /*=================================*/ 
    /*==Increment the line index by 1==*/ 
    /*=================================*/ 
    $lineindex++; 
    
    /*============================================*/ 
    /*====== Your results layout goes here =======*/ 
    /*============================================*/ 
    
    $id=$result ['id']; 
    $name=$result ["name"]; 
    $url=$result ["url"]; 
    $price_d=$result ["price"]; 
    $records_d=$result ["records"]; 
    $members_d=$result ["members"]; 
    $description=$result ["description"]; 
    $rating=$result ["rating"]; 
    
    
    print ($result % 2) ? "<tr bgcolor=\"#FFFFFF\">" : "<tr bgcolor=\"#d3d3d3\">"; 
    echo "<td align=middle><A HREF=\"$url\" target=\"_blank\">$name</A></td><td align=middle>$price_d</td>"; 
    print "<td align=middle>$records_d</td>"; 
    print "<td align=middle>$description</td>"; 
    print "<td align=middle>$rating</td>"; 
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you soo much!!!
    I really mean it, this actually make alot more sense to me now.

    Thanks again for the help.


Bookmarks

Posting Permissions

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