SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selection and Results...

    Hello, I have problem. No matter what is selected, only "season01" data is displayed. If "Season 02" is selected, season01 displays, same with Season 03.

    Here is the drop down menu:

    <select name="pastseasonpoints">
    <option value="season01">Season 01</option>
    <option value="season02">Season 02</option>
    <option value="season03">Season 03</option>
    </select>

    and the output is:
    PHP Code:
    <table class="userstats" border="1" style="width:490px;">
    <tr class="userstatstableheader">
    <td>Pos.</td><td>Driver</td><td>Pts</td><td>Behind</td><td>Bonus</td>
    <td>Events</td><td>Wins</td><td>Poles</td><td>Laps</td><td>Led</td><td>Led%</td><td>Top5</td><td>Top10</td><td>DNS</td><td>DNF</td></tr>
    <?php
    if ($_Post['pastseasonpoints'] = "season01" ) {
    $query "SELECT * FROM season01 ORDER BY Position";
    }
    elseif (
    $_Post['pastseasonpoints'] = "season02" ) {
    $query "SELECT * FROM season02 ORDER BY Position";
    }
    elseif (
    $_Post['pastseasonpoints'] = "season03" ) {
    $query "SELECT * FROM season03 ORDER BY Position";
    }

    $result mysql_query($query);
    if (!
    $result) { echo("<p>Error performing query: " mysql_error() . "</p>" );
    exit(); }
    while ( 
    $row mysql_fetch_array($result) ) {
    echo(
    "<tr class=\"userstats\"><td>" $row["Position"] . "</td>" );
    echo(
    "<td>" $row["Driver"] . "</td>" );
    echo(
    "<td>" $row["Points"] . "</td>" );
    echo(
    "<td>" $row["Points_Behind"] . "</td>" );
    echo(
    "<td>" $row["Bonus"] . "</td>" );
    echo(
    "<td>" $row["Events"] . "</td>" );
    echo(
    "<td>" $row["Wins"] . "</td>" );
    echo(
    "<td>" $row["Poles"] . "</td>" );
    echo(
    "<td>" $row["Laps"] . "</td>" );
    echo(
    "<td>" $row["Led"] . "</td>" );
    echo(
    "<td>" $row["Led_Percent"] . "</td>" );
    echo(
    "<td>" $row["Top5"] . "</td>" );
    echo(
    "<td>" $row["Top10"] . "</td>" );
    echo(
    "<td>" $row["DNS"] . "</td>" );
    echo(
    "<td>" $row["DNF"] . "</td></tr>" );
    }
    ?>
    </table>
    Any idea why?

    Thank you.
    Troy

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    You need to use == instead of =. See below for the amended code:
    PHP Code:
    <?php
    if ($_Post['pastseasonpoints'] == "season01" ) {
    $query "SELECT * FROM season01 ORDER BY Position";
    }
    elseif (
    $_Post['pastseasonpoints'] == "season02" ) {
    $query "SELECT * FROM season02 ORDER BY Position";
    }
    elseif (
    $_Post['pastseasonpoints'] == "season03" ) {
    $query "SELECT * FROM season03 ORDER BY Position";
    }
    ?>
    Hope this helps [img]images/smilies/smile.gif[/img]

    -Sam
    Sam Hastings

  3. #3
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am getting this error: Error performing query: Query was empty

    using the following:
    Form:

    <select name="pastseasonpoints">
    <option value="season01">Season 01</option>
    <option value="season02">Season 02</option>
    <option value="season03">Season 03</option>
    </select>


    Results Page:
    PHP Code:
     <table class="userstats" border="1" style="width:490px;">
    <tr class="userstatstableheader">
    <td>Pos.</td><td>Driver</td><td>Pts</td><td>Behind</td><td>Bonus</td><td>Events</td>
    <td>Wins</td><td>Poles</td><td>Laps</td><td>Led</td><td>Led%</td><td>Top5</td><td>Top10</td><td>DNS</td><td>DNF</td></tr>
    <?php
    $db 
    "hfrl0303_league";
    $dbhost "localhost";
    $dbuser "";
    $dbpass "";
    $Host "localhost";
    $User "";
    $Password "";

    $Link mysql_connect ($dbhost$dbuser$dbpass);

    if (!
    $Link)
    {
    echo 
    "Error: Could not connect to the database. Please try again.";
    exit;
    }

    if (! @
    mysql_select_db($db) ) {
    echo( 
    "Unable to locate the Forum Database at this time." );
    exit ();
    }
    if (
    $_Request['pastseasonpoints'] == "season01" ) {
    $query "SELECT * FROM season01 ORDER BY Position";
    }
    elseif (
    $_Request['pastseasonpoints'] == "season02" ) {
    $query "SELECT * FROM season02 ORDER BY Position";
    }
    elseif (
    $_Request['pastseasonpoints'] == "season03" ) {
    $query "SELECT * FROM season03 ORDER BY Position";
    }
    $result=mysql_query($query$Link);
    if (!
    $result) { 
    echo(
    "<p>Error performing query: " mysql_error() . "</p>" ); 
    exit(); 
    }
    while (
    $row = @mysql_fetch_array($resultMYSQL_ASSOC)) {
    echo(
    "<tr class=\"userstats\"><td>" $row["Position"] . "</td>" );
    echo(
    "<td>" $row["Driver"] . "</td>" );
    echo(
    "<td>" $row["Points"] . "</td>" );
    echo(
    "<td>" $row["Points_Behind"] . "</td>" );
    echo(
    "<td>" $row["Bonus"] . "</td>" );
    echo(
    "<td>" $row["Events"] . "</td>" );
    echo(
    "<td>" $row["Wins"] . "</td>" );
    echo(
    "<td>" $row["Poles"] . "</td>" );
    echo(
    "<td>" $row["Laps"] . "</td>" );
    echo(
    "<td>" $row["Led"] . "</td>" );
    echo(
    "<td>" $row["Led_Percent"] . "</td>" );
    echo(
    "<td>" $row["Top5"] . "</td>" );
    echo(
    "<td>" $row["Top10"] . "</td>" );
    echo(
    "<td>" $row["DNS"] . "</td>" );
    echo(
    "<td>" $row["DNF"] . "</td></tr>" );
    }
    ?>
    </table>
    I used = = this time, no luck. If I use 1 "=" it returns season 01 regardless of the selection made. Any ideas?
    Last edited by Knightime; Apr 12, 2003 at 16:50.
    Troy

  4. #4
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, I tried reversing the statement like so:

    if ("season01" == $_Request['pastseasonpoints'])

    No luck, please help.
    Troy

  5. #5
    SitePoint Zealot jgreen's Avatar
    Join Date
    Apr 2003
    Location
    everywhere and nowhere
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you use = as apposed to == your not comparing, your assigning. so make sure and use == or === the difference is that === pays attention to type. You should be fine with ==.

    As for your empty query. try echoing $query just befor you call mysql_query and see if the sql is actually coming out right. If so, the dump that sql statement and see if it works in phpMyAdmin.

    the results of this test will tell you for sure where the problem lies.

  6. #6
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added this line as you suggested. I get the same error. Am I doing something wrong:

    echo ($query);


    btw, where the heck did the "reply" button go in this forum?!
    Troy

  7. #7
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone..?
    Troy

  8. #8
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this a challenge too difficult or something? What's going on here? I have been stuck with this basic function for a whille and no one seems to want to help much. Some people rewrite entire pages of code for others, I can barely get a one-liner nowadays. What gives?
    Troy

  9. #9
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So the "echo $query" writes nothing?

    You may want to try changing $_Request['pastseasonpoints']) to $_REQUEST['pastseasonpoints']. Though I'm doubtful that is the problem.

    I suggest you print out the value of $_REQUEST['pastseasonpoints']. And see what it gives you.


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
  •