Please i need help with searching criteria

Discussion in 'Software' started by Alderan, Nov 2, 2005.

  1. Alderan

    Alderan Private E-2

    Well first of all i have to say i have no idea of what i did wrong but also add that i have really low php and mysql skills. Well the fact is that i was making a search form like the one in http://www.pgtour.net to make the replays of my games searchable. Well following the manuals and tutorials i found i made a code and im able to find acording to 1 criteria the rest wont work. I mean i can search by losers name for example but it wont let me by winners name.
    The link to the code in actio is this: http://alderan.al.funpic.de/poop.php

    <?php
    if(!$c) {
    ?><style type="text/css">
    <!--
    body,td,th {
    color: #FFFFFF;
    }
    body {
    background-color: #2C333D;
    }
    -->
    </style>
    <form action="poop.php?c=1" method=POST>
    <p><b>Find replays by : </b><br>
    <input type="text" length=40 name="winner">
    Winner Nick <br>
    <input type="text" length=40 name="loser">
    Loser Nick <br>
    <input type="text" length=40 name="winrace">
    Winner Race <br>
    <input type="text" length=40 name="map">
    Map <br>
    <br>
    <input type="submit" value="Buscar">
    </p>
    </form>
    <?
    } else if($c) {
    MySQL_connect("localhost", "alderan", "mypass");
    MySQL_select_db("alderan");
    if((!$winner) || ($winner == "")) { $winner = ""; } else { $winner = "+(".$winner.")"; }
    $query = "
    SELECT player1, player2, races, map,
    MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE)";
    if((!$loser) || ($loser == "")) { $loser = ""; } else { $loser = "+(".$loser.")"; }
    $query = "
    SELECT player1, player2, races, map,
    MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE)";
    $artm1 = MySQL_query($query);
    if(!$artm1) {
    echo MySQL_error()."<br>$query<br>";
    }
    echo "<b>Resultado de la Busqueda</b><br>";
    if(MySQL_num_rows($artm1) > 0) {
    echo "<table>";
    echo "
    <tr>
    <td>Winner</td>
    <td>Loser</td>
    <td>Map</td>
    <td>Match</td>
    <td>Date</td>
    <td>Download</td></tr>";
    while($artm2 = MySQL_fetch_array($artm1)) {
    echo "<td>{$artm2['player1']}</td>";
    echo "<td>{$artm2['player2']}</td>";
    echo "<td>{$artm2['map']}</td>";
    echo "<td>{$artm2['races']}</td>";
    echo "<td>{$artm2['date']}</td>";
    echo "<td>{$artm2['download']}</td></tr>";
    }
    echo "</table>";
    }
    else {
    echo "No Results were found in this category.<br>";
    }
    echo "<br>";
    }
     
  2. Wookie

    Wookie Sergeant Major

    looking at
    Code:
    if((!$winner) || ($winner == "")) { $winner = ""; } else { $winner = "+(".$winner.")"; }
    $query = "
    SELECT player1, player2, races, map,
    MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE)";
    if((!$loser) || ($loser == "")) { $loser = ""; } else { $loser = "+(".$loser.")"; }
    $query = "
    SELECT player1, player2, races, map,
    MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE)";
    You first IF ends if((!$winner) || ($winner == "")) { $winner = ""; } else { $winner = "+(".$winner.")"; } ----HERE

    so that query is made
    $query = "
    SELECT player1, player2, races, map,
    MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE)";


    No Matter what the value of winner is, the same thing for loser, except

    $query = "
    SELECT player1, player2, races, map,
    MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE)";


    Is executed no matter what, so as far as I can tell you SHOULD be able to only search by loser, because $query is overwritten with the loser SQL every time.


    An easier way to view your code:


    MySQL_connect("localhost", "alderan", "mypass");
    MySQL_select_db("alderan");
    if((!$winner) || ($winner == ""))
    {
    $winner = "";
    }
    else
    {
    $winner = "+(".$winner.")";
    }
    $query = "SELECT player1, player2, races, map, MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE) AS score FROM replays
    WHERE MATCH(player1) AGAINST ('$winner' IN BOOLEAN MODE)";

    if((!$loser) || ($loser == ""))
    {
    $loser = "";
    }
    else
    {
    $loser = "+(".$loser.")";
    }

    $query = "SELECT player1, player2, races, map,
    MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE) AS score FROM replays
    WHERE MATCH(player2) AGAINST ('$loser' IN BOOLEAN MODE)";

    $artm1 = MySQL_query($query);

    if(!$artm1) {
    echo MySQL_error()."<br>$query<br>";
    }



    As you can see now that its a bit easier to read, Query gets assigned the SQL query searching against winner, then gets reassigned the loser query so by the time you get to

    $artm1 = MySQL_query($query);

    You will always have the loser query.



    Make any sense?
     
  3. Alderan

    Alderan Private E-2

    but how do i fix it :(
     
  4. Wookie

    Wookie Sergeant Major

    It would probably involve the query text only being set when a condition is met instead of having it set twice.
     
  5. Alderan

    Alderan Private E-2

    Still Dont Know :(
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds