PDA

View Full Version : MySQL query, PHP variable


PeF
Fri 26th Jan '01, 7:09am
$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.

Rickard
Fri 26th Jan '01, 7:22am
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.

PeF
Fri 26th Jan '01, 8:47am
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.

Rickard
Fri 26th Jan '01, 9:48am
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" );

PeF
Fri 26th Jan '01, 9:59am
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. :D

Big thanks. It works perfectly now. ;)