SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    while ($row = mysql_fetch_array ($res)) not a valid MySQL result?

    I'm trying to find a query that works for me, but one that shows some promise apparently has a conflict with another line in my script. This query...

    PHP Code:
    $res mysql_query("SELECT GROUP_CONCAT(DISTINCT Area SEPARATOR ', ') as Area, Class, OrderCommon `Order` FROM symbols
      WHERE Class = '
    $myname' ORDER BY `Order` GROUP BY Area"); 
    produces this error message:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\sites\GeoSymbols\a1\articles\ani\tableclass.php on line 78

    And this appears to be the line it refers to:

    PHP Code:
    while ($row mysql_fetch_array ($res)) { 
    For some reason, I don't get that error when I use this query:

    PHP Code:
    $res mysql_query("SELECT DISTINCT(`Order`), Area, Class, OrderCommon FROM symbols
    WHERE Class = '
    $myname' GROUP BY `Order` ORDER BY `Order`"); 
    Unfortunately, that query doesn't do exactly what I want it to. Anyway, here's the entire script, from the query down to the problem line. Can anyone tell me how to fix it?

    Thanks.

    PHP Code:
    // if type contains content then print out list
    $result mysql_query('select count(*) from symbols');
    if ((
    $result) && (mysql_result ($result 0) > 0)) {
    } else {
    die(
    'Invalid query: ' mysql_error());
    }
    {

    $res mysql_query("SELECT GROUP_CONCAT(DISTINCT Area SEPARATOR ', ') as Area, Class, OrderCommon `Order` FROM symbols
      WHERE Class = '
    $myname' ORDER BY `Order` GROUP BY Area");

    echo 
    '<table class="sortphp_ref" id="TableTax" style="margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;">
    <thead>
    <tr><th style="background: #666; color: #fff;">Places</th>
    <th style="background: ' 
    $BG '; color: #fff;">Orders</th></tr>
    </thead>
    <tbody>'
    ;
    //<!-- BeginDynamicTable -->
    {
    while (
    $row mysql_fetch_array ($res)) { 

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    $res 
    mysql_query("SELECT GROUP_CONCAT(DISTINCT Area SEPARATOR ', ') as Area, Class, OrderCommon `Order` FROM symbols WHERE Class = '$myname' ORDER BY `Order` GROUP BY Area"); 

    if ( 
    mysql_errno() > ) {
      echo 
    mysql_error();
      exit;
    }
    else { 

      while ( 
    $row mysql_fetch_array$res ) ) {

       ....
      }


  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May I ask what 'GROUP_CONCAT' is used for, I have never seen it before, and searches in the MySQL manual has not turned up anything?

    Thanks,
    Itshim

  4. #4
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind, I just found it.

    Thanks,
    Itshim

  5. #5
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I must have implemented it wrong. I had to delete some brackets from the very end of the script to get rid of some parse errors. Now I get this error message:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY Area' at line 2

    Also, the closing PHP tag (?>) is "dead"; it's faded out, indicating problem somehwere above.

    Thanks.

    PHP Code:
     $res mysql_query("SELECT GROUP_CONCAT(DISTINCT Area SEPARATOR ', ') as Area, Class, OrderCommon `Order`
      FROM symbols WHERE Class = '
    $myname' ORDER BY `Order` GROUP BY Area");

    if ( 
    mysql_errno() > ) {
      echo 
    mysql_error();
      exit;
    }
    else {

      while ( 
    $row mysql_fetch_array$res ) ) {


    echo 
    '<table class="sortphp_ref" id="TableTax" style="margin: 0px auto 25px; border-bottom: 1px solid #000; font-size: 85%;">
    <thead>
    <tr><th style="background: #666; color: #fff;">Places</th>
    <th style="background: ' 
    $BG '; color: #fff;">Orders</th></tr>
    </thead>
    <tbody>'
    ;
    //<!-- BeginDynamicTable -->

    // Adjust it for bony fishes...
    switch ($Animals['Class']) {
    case 
    'Osteichthyes':
    $LinkSymbol '/animals/fishes/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    default:
    $LinkSymbol '/animals/' strtolower($row["ClassCommon"]) . '/' strtolower(substr($row["Order"],0,3)) . '/';
    break;
    }

    $ast '<a href="#Notes">*</a>';
    if(
    $row['elevnotes'] ==''):
    $ast '';
    endif;
    // <td class="tdname" style="background: $BGRow">{$row["Area"]}</td>

    echo <<<EOD
       <tr class="$c {$row["IDParent2"]} {$row["DesigGeneral"]}" id="$mycodeID" style="background-color:$c">
         <td class="tdname" style=\"background-color:
    $color\">{$row["Area"]}</td>
         <td class="tdsymbol"><a href="
    $LinkSymbol">{$row["Order"]}</a> ({$row["OrderCommon"]})</td>
       </tr>
    EOD;
    }
    }
    ?>
    </tbody>
    </table> 

  6. #6
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind; I solved it. Thanks.


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
  •