Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7

Thread: mySQL Query

  1. #1
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    PHP Code:
    $ThingName mysql_query(" SELECT ThingName FROM tbleThing WHERE ThingID = ".$ThingID.""); 
    tbleThing only has 2 fields, ThingName and ThingID. $ThingID is a var that has in it an ID # from the table. The above code is supposed to just grab the name that's associated with the ID #, but errors out. I'm pretty sure it has to do with the way the variable is in there, but I'm too tired to see what's wrong. Anyone want to point it out? Thanks.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    You really don't need last two quotations.

    PHP Code:
    $ThingName mysql_query("SELECT ThingName FROM tbleThing WHERE ThingID = ".$ThingID); 
    There and Back Again :Ogre:

  4. #3
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Still doesn't work.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  5. #4
    Senior Member ceetee's Avatar
    Join Date
    Jul 2003
    Posts
    117
    Member #
    2035
    Try this

    $ThingName = mysql_query("SELECT ThingName FROM tbleThing WHERE ThingID = '$ThingID'");

    or leave out the single quotes if it's a number.

  6. #5
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Figured that error out, previous page wasn't passing value, my bad.

    PHP Code:
    $ThingName mysql_query(" SELECT ThingName FROM tbleThing WHERE ThingID = ".$ThingID);
    if ( 
    mysql_error() ) { print "Database ERROR2: " mysql_error(); } 
    Code:
    <tr>
    <td>Thing Type:</td>
    <td><? echo "$ThingName" ?></td>
    </tr>
    Here's what the above code does print out:
    Thing Name: Resource id #4

    While it is the 4th thing in the printout list, I don't know why it's printing out resource ID #4.

    Right below that code is the same code again, and it prints out the same thing, but resource ID #5. The first 3 in the printout list are fine.

    Ideas? I have confirmed that ThingID's value is valid and correct. I've also ran "SELECT ThingName FROM tbleThing WHERE ThingID = 1" directly on the database, and it works fine as well, so it's the PHP code...
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    PHP Code:
    <?php
    $result 
    mysql_query(" SELECT ThingName FROM tbleThing WHERE ThingID = ".$ThingID);
    if (
    $row mysql_fetch_array($result)) {
    ?>
    <tr>
    <td>Thing Type:</td>
    <td><? echo $row['ThingName'?></td>
    </tr>
    <?
    }
    if ( 
    mysql_error() ) {
         print 
    "Database ERROR2: " mysql_error(); 
    }
    ?>

  8. #7
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Thanks to Transio, it's ALIVE!!! MWAHAHAHAHAHAHA!!!!
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:08 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com