SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php& mysql seacrh problem

    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. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    the problem is first you build the query using the $winner variable. then you build the query again, but using the $loser variable instead. in the process, you have overwritten your query.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ?

    how do i fix it?

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh come on it takes the same time to say the refere link taht you posted that to help me with this, i getting depressed pal...

  5. #5
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    wow, talk about impatient. you know we do this for free in our spare time, right? your kind of attitude and poor 'netiquite get your posts ignored.
    PHP Code:
    <?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");
    $query "
    SELECT player1, player2, races, map,
    MATCH(player1) AGAINST ('
    $winner' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE 1=1"
    if (is_set($winner)) {
    $query .= " or MATCH(player1) AGAINST ('+$winner' IN BOOLEAN MODE)";
    }
    if (
    is_set($loser)) {
    $query .= " or MATCH(player1) 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>";
    }

  6. #6
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i missed a semi-colon on line 35. corrected code:
    PHP Code:
    <?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");
    $query "
    SELECT player1, player2, races, map,
    MATCH(player1) AGAINST ('
    $winner' IN BOOLEAN MODE) AS score
    FROM replays
    WHERE 1=1"
    ;
    if (
    is_set($winner)) {
    $query .= " or MATCH(player1) AGAINST ('+$winner' IN BOOLEAN MODE)";
    }
    if (
    is_set($loser)) {
    $query .= " or MATCH(player1) 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>";
    }

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now it wont search, it just shows all entries no matter the values of the text boxes

  8. #8
    Not yet perfect mattalexx's Avatar
    Join Date
    Oct 2005
    Location
    Taos, NM, US
    Posts
    441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you had said thanks to him, he might have gone the extra mile.


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
  •