+ Reply to Thread
Results 1 to 6 of 6

Thread: more multiple queries

  1. #1
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    more multiple queries

    ok i am back working on my search feature for my games, the problem i am having is i am getting no results back... here is my code:

    Code:
    <?php
    require ('../../../dbgames_connect.php');
    $min=600;
    foreach (str_split('GFEDCBAXM') as $class) {
        $classmin[$class] = $min;
        $classmax[$class] = $min+199;
        $min+=200;
    }
    $classmax['M']="3000";
    $classmin['Z']="600";
    $classmax['Z']="3000";
    
    if (!$_POST['search'])
        {
    ?>
            <form method="post" style="text-align: center;" action="gamesb.php" target="_self">
            Search Games, for help and tips <a href="help.htm" target="_blank">click here</a>.<br>
            White:<br>
            First Name:  
            <input name="wFirst" type="text" tabindex="1"><br>
            Last Name:
            <input name="wLast" type="text" tabindex="2"><br>
            Rating:
            <input name="wRating" type="text" tabindex="3" style="height: 22px" size="8">&nbsp;OR:&nbsp; 
            <select name="wClass" tabindex="4" style="height: 22px">
            <option value="Z" selected="">Select Class</option>
            <option>G</option>
            <option>F</option>
            <option>E</option>
            <option>D</option>
            <option>C</option>
            <option>B</option>
            <option>A</option>
            <option value="X">Expert</option>
            <option value="M">Master+</option>
            </select><br>
            <br>
            Black:<br>
            First Name:
            <input name="bFirst" type="text" tabindex="5"><br>
            Last Name:
            <input name="bLast" type="text" tabindex="6"><br>
            Rating:
            <input name="bRating" type="text" tabindex="7" size="8" style="height: 22px">&nbsp;OR:&nbsp;
            <select name="bClass" tabindex="8">
            <option value="Z" selected="">Select Class</option>
            <option>G</option>
            <option>F</option>
            <option>E</option>
            <option>D</option>
            <option>C</option>
            <option>B</option>
            <option>A</option>
            <option value="X">Expert</option>
            <option value="M">Master+</option>
            </select><br>
            <br>
            Game Info:<br>
            Eco:
            <input name="eco" type="text" tabindex="9" size="6"> (<a target="_blank" href="ecocodes.htm">help</a>)<br>
            Year:
            <input name="year" type="text" tabindex="10" size="8">
            <select name="result" tabindex="11">
            <option value="3">Select Result</option>
            <option value="1">1-0</option>
            <option value="0">0-1</option>
            <option value="2">1/2-1/2</option>
            </select>
            <br>
            <input name="search" type="submit" value="search" tabindex="12"></form>
    <?php
                }
        else { 
            $wValue=$_POST['wClass'];
            $bValue=$_POST['bClass'];
            $wRatingmin=$classmin[$wValue];
            $wRatingmax=$classmax[$wValue];
            $bRatingmin=$classmin[$bValue];
            $bRatingmax=$classmax[$bValue];
            if ($_POST['wFirst'])
                {$wFirst=sanitize_lower($_POST['wFirst']);
                $restraints[]="wFirst LIKE '$wFirst'";}
            if ($_POST['wLast'])
                {$wLast=sanitize_lower($_POST['wLast']);
                $restraints[]="wLast LIKE '$wLast'";}
            if ($_POST['bFirst'])
                {$bFirst=sanitize_lower($_POST['bFirst']);
                $restraints[]="bFirst LIKE '$bFirst'";}
            if ($_POST['bLast'])
                {$bLast=sanitize_lower($_POST['bLast']);
                $restraints[]="bLast LIKE '$bLast'";}
            if ($_POST['eco'])
                {$eco=strtoupper(sanitize($_POST['eco']));
                $restraints[]="eco LIKE '$eco'";}
            if ($_POST['year'])
                {$year=$_POST['year'];
                $restraints[]="year LIKE '$year'";}
            if ($_POST['wRating'])
                {$wRating=$_POST['wRating'];
                $restraints[]="wRating LIKE '$wRating'";}
            if ($_POST['bRating'])
                {$bRating=$_POST['bRating'];
                $restraints[]="bRating LIKE '$bRating'";}
            if ($_POST['result'])
                {$result=$_POST['result'];
                if($result!=3)
                    {
                    $restraints[]="result LIKE '$result'";
                    }
                }
            $restraints[]="wRating>='{$wRatingmin}'";
            $restraints[]="wRating<='{$wRatingmax}'";
            $restraints[]="bRating>='{$bRatingmin}'";
            $restraints[]="bRating<='{$bRatingmax}'";
            $restraints = 'WHERE ' . implode(' AND ', $restraints);
            echo $restraints;
            $query = mysql_query("SELECT * FROM games $restraints") or die(mysql_error());
            ?>
            <center>
            <?php          
                echo "<ol>";
                while($row = mysql_fetch_array($query))
                    {
                    $n = $row['id'];
                    $result = $row['result'];
                    $result = result($result);
                    echo "<li><a href=\"javascript:LoadNextPage($n,1)\" class='game'>".$row['wLast']." (".$row['wRating'].") - ".$row['bLast']." (".$row['bRating'].")<br>";
                    echo $row['eco']." ".$row['result']."</a></li>";                      
                    }
                 echo "</ol>";

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

    Re: more multiple queries

    I would have one thing to say. Try to separate php code and html code (MVC), it's way better than trying to put everything in the same file. Next, I would not recommend transforming an array into a string, even though php is loose on variable types. Try renaming the 'restraints' string to 'restraint'. Also, to test your query, echo it, then try it in phpMyAdmin.
    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

  3. #3
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: more multiple queries

    Quote Originally Posted by xav0989 View Post
    I would have one thing to say. Try to separate php code and html code (MVC), it's way better than trying to put everything in the same file. Next, I would not recommend transforming an array into a string, even though php is loose on variable types. Try renaming the 'restraints' string to 'restraint'. Also, to test your query, echo it, then try it in phpMyAdmin.
    ok i made your suggested change, when i echo the query and run in in phpmyadmin it works fine

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

    Re: more multiple queries

    does the page still shows problems? If so, it is something with your variables (maybe doing = instead of .= ) or it's something with your control flow operators.
    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

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

    Re: more multiple queries

    Quote Originally Posted by garrensilverwing View Post
    ok i made your suggested change, when i echo the query and run in in phpmyadmin it works fine
    For the line $query = mysql_query("SELECT * FROM games $restraints") or die(mysql_error());, am I right in assuming the query succeeds, but it returns an empty result set? What's the query? Try creating a simple PHP script that runs that query. There are still some missing pieces to this puzzle.

    Quote Originally Posted by garrensilverwing View Post
    PHP Code:
            if ($_POST['wFirst'])
                {
    $wFirst=sanitize_lower($_POST['wFirst']);
                
    $restraints[]="wFirst LIKE '$wFirst'";}
            if (
    $_POST['wLast'])
                {
    $wLast=sanitize_lower($_POST['wLast']);
                
    $restraints[]="wLast LIKE '$wLast'";}
            
    // ...
            
    if ($_POST['bRating'])
                {
    $bRating=$_POST['bRating'];
                
    $restraints[]="bRating LIKE '$bRating'";} 
    This long section can be replaced with
    PHP Code:
    // in whichever file defines sanitize_lower:
    function sanitize_int($val) {
      return 
    filter_var($valFILTER_SANITIZE_NUMBER_INT);
    }

    // in the search form handler:
    $bRatingmax=$classmax[$bValue];
    foreach (array(
    'wFirst' => 'sanitize_lower''wLast' => 'sanitize_lower',
               
    'bFirst' => 'sanitize_lower''bLast' => 'sanitize_lower'
               
    'eco' => 'sanitize_upper''year' => 'sanitize_int'
               
    'wRating' => 'sanitize_int''bRating' => 'sanitize_int')
         as 
    $field => $func
    {
      
    $val call_user_func($func$_POST[$field];
      
    $restraints[] = "$field LIKE '$val'";
    }
    if (
    $_POST['result']) 
    sanitize_upper() needs to be defined, which can be done by a simple modification of a copy of sanitize_lower().

    Quote Originally Posted by xav0989 View Post
    Next, I would not recommend transforming an array into a string, even though php is loose on variable types.
    Is your reason for this because when examining a line of source code, you won't be able to tell exactly what a variable holds without examining all the preceding lines? That is, storing different types in the same variable increases interdependecies between lines.

  6. #6
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: more multiple queries

    ok i figured it out, i forgot to define function result() i put it as part of another file to be called upon but i didnt require it at the beginning of this one, it works perfectly now

+ Reply to Thread

Similar Threads

  1. multiple queries
    By garrensilverwing in forum Programming Help
    Replies: 12
    Last Post: 05-12-2009, 08:24 PM
  2. Multiple Forum / Hosting Account Links
    By Bryon in forum News and Announcements
    Replies: 10
    Last Post: 04-02-2009, 02:02 AM
  3. Date/Calendar functions and parameterized queries help needed.
    By parkourmumbai in forum Programming Help
    Replies: 16
    Last Post: 10-15-2008, 12:51 AM
  4. Bid For Multiple Background Dynamic SIG
    By iubtalks in forum The Marketplace
    Replies: 32
    Last Post: 08-05-2006, 01:28 PM

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