Quote:
Originally Posted by kamu
I'm really new at PHP, I just bought a book to help me modify my boards a little bit. To practice, I tried calling user ID #1 from the database and posting it on the forum home.
I know this may look way off but here's what I did.
PHP Code:
// Locate Forum Administrator
$findadmin = mysql_query ($adminquery);
$adminquery = "SELECT username FROM user WHERE userid = '1'";
$whosadmin = "The administrator of this forum is $findadmin";
I added this into index.php and added the variable $whosadmin to the forumhome template.
It's appearing on my board as "The administrator of this forum is" - and stops at the good part >.<
What did I miss or where did I mess up?
|
Except for the query (but there's a slight problem there too), you are off.
The correct code:
PHP Code:
$result = mysql_query("SELECT username FROM user WHERE userid = 1");
$user = mysql_fetch_array($result);
$adminusername = $user['username'];
$admintext = "The administrator of this forum is $adminusername.";
What I changed (other than some variable names but yours are not that bad):
- The correct procedure is execute the query, saving the result to a variable, and then save the result of mysql_fetch_array(that result) to another variable. mysql_fetch_array() returns one resulting row of the query as an array, where each array key corresponds to a column name in the query.
- Do not use quotes for numeric columns in MySQL.
If you are using a vB-powered page, then replace mysql_query() with $DB_site->query() and mysql_fetch_array() with $DB_site->fetch_array().[/list]