SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A table names "Columns"

    Okay, this is strange

    I have a table named "columns", however i get the following error when I try to access it:

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in columns.php on line 6
    anyway, I could not for the life of me work out why, and in the end I dropped the table and made a new one with a different name (ctcolumns) which works (with exactly the same php code, bar the table name changed in the query).

    Just to settle my curiousity, I renamed the table back to columns (and adjusted the query to match) and it doesn't work again

    Is "columns" a special mysql word you can't use?

    The code I was using to extract the data is pretty simple:

    PHP Code:
    <table>

    <?
    include('connect.php');
    $getcolumns mysql_query("SELECT * FROM ctcolumns");
    while (
    $cinfo mysql_fetch_array($getcolumns))
    {
        
    $cid $cinfo['ctcolumnID'];
        
    $cauthor $cinfo['author'];
        
    $ctitle $cinfo['columntitle'];
        
    ?>
        
        <tr>
            <td width="8" valign="center"><img src="images/arrow.gif" width="8"></td>
            <td><a href="viewcolumn.php?columnid=<?=$cid?>"><?=$ctitle?></a></td>
        </tr>
        
        <?    
    }
    ?>

    </table>
    very strange indeed!

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why yes it is a reserved word

    http://www.mysql.com/doc/en/Reserved_words.html

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I know that in SQL Server, if somebody has made a table and named it after a reserved word (i.e. date, user), you can wrap the tablename in brackets to execute the query:
    Code:
    $SQL = "SELECT * FROM [User] WHERE UserID=$uid;";
    Try that and see if it works, if you don't want to change your table/field name.

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would be backticks (`) in MySQL
    Code:
    SELECT field FROM `columns`...
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  5. #5
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I never know mysql had reserved words... hmm, okay

    I just renamed the table, so it's no drama, I was just confused


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
  •