Announcement

Collapse
No announcement yet.

MySQL query, PHP variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL query, PHP variable

    $variable=$DB_site->query("SELECT something FROM user WHERE <what should be here?>");

    include("a_$variable.php");

    returns:

    Warning: Failed opening 'a_Resource id #16.php' for inclusion (include_path='') in <my path> on line 16


    I added a new column to user table (type CHAR, lenght 3, not null, default abc). I thought I can simply query the variable from the db and use it as seen above.
    Can anyone help me solve this?

    Thanks in advance.

  • #2
    After a query you have to fetch the info from the db with mysql_fetch_array() or mysql_fetch_row() or some other function. I believe vBulletin has it's own fetching routines in the DB-class. I think you could do it like this.


    $result = $DB_site->query( "SELECT something FROM user WHERE $userid=1" );
    $variable = $DB_site->fetch_array( $result );

    include( 'a_'.$variable[something].'.php' );


    Since fetch_array returns an array, you have to use $variable[field] to access it's values.

    <what should be here?> should be replaced with some information that separates the record you are looking for from other records. Perhaps a userid as I did.

    Comment


    • #3
      I really appreciate your quick and very helpful response.
      Got the point but one more error has occured:

      Failed opening 'lang-'.abc.'.php' for inclusion ......
      using this syntax

      $getsomething=$DB_site->query("SELECT something FROM user WHERE userid=1");
      $variable=$DB_site->fetch_array($getsomething);
      include("a-'.$variable[something].'.php");

      Code
      include('a-'.$variable[something].'.php');
      returns Cannot redeclare db_class on line ....

      Code
      include("$variable[something].php");
      returns correct value but I'd like to use an "a" before $variable.


      Thanks again, Rickard.

      Comment


      • #4
        Hmmm.

        If the variable $variable[something] contains a string like "test", the code I wrote

        include( 'a_'.$variable[something].'.php' );

        will include the file a_test.php. I don't know why it didn't work for you.


        Thy this then:

        include( "a-$variable[something].php" );

        Comment


        • #5
          Originally posted by Rickard
          I don't know why it didn't work for you.
          Because I forgot to remove require("global.php"); from the a-test.php file. Silly me.

          Big thanks. It works perfectly now.

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X