View Full Version : How to call a Profile field in a php file?
neocorteqz
03-16-2005, 10:49 PM
I'm trying to create a webcam script, and would like to use a hidden profile field where the member can enter his/her address to the webcam and it will automatically add to the page.
How could one accomplish this smartly, and what would be the query to select from a certain field? i know how to call from a field in a template, but don't know how to accomplish this in a php file.
thanks.
Adrian Schneider
03-16-2005, 11:17 PM
Just run a query... Off the top of my head:
$cache=$DB_site->query_first("SELECT fieldX FROM userfield WHERE userid=Y");
Typing $cache[fieldX] would display the field.
I'm not sure what mroe you want, but this should do the main part.
neocorteqz
03-16-2005, 11:25 PM
Just run a query... Off the top of my head:
$cache=$DB_site->query_first("SELECT fieldX FROM userfield WHERE userid=Y");
Typing $cache[fieldX] would display the field.
I'm not sure what mroe you want, but this should do the main part. actually from all users that have that field filled in if it's possible. afterall I would think scanning empty rows would not cause undue stress.
So i would drop the WHERE userid=X and it would scan for all?
Ohh, and thanks. :)
Adrian Schneider
03-17-2005, 12:26 AM
Pretty much, yes.
You actually need to run a while. Try this:
$query = $DB_site->query("SELECT fieldX FROM userfield");
while($array=$DB_site->fetch_array($query))
{
$webcamurl = $array['fieldX'];
// Declare anything else here
$webcamurlbit .= "$webcamurl" . '<BR>';
}
Or a template based one:
$query = $DB_site->query("SELECT fieldX FROM userfield");
while($array=$DB_site->fetch_array($query))
{
$webcamurl = $array['fieldX'];
// Declare anything else here
eval('$variable = "' . fetch_template('template_name') . '";');
}
For the second one, you'd create a template and inlclude anything you want repeated inside of it (could be rows of a table (including the $webcamurl)). Then just insert $variable into your main template, and it will repeat the contents.
Edit: by the way, if your php file isn't associated with vBulletin (doesn't include global.php) you have to use mysql_query instead of $DB_site->query and mysql_fetch_array instead of DB_site->fetch_array. Also, if this is the case, you can't use templates, obviously. :)
neocorteqz
03-17-2005, 02:04 AM
Pretty much, yes.
You actually need to run a while. Try this:
$query = $DB_site->query("SELECT fieldX FROM userfield");
while($array=$DB_site->fetch_array($query))
{
$webcamurl = $array['fieldX'];
// Declare anything else here
$webcamurlbit .= "$webcamurl" . '<BR>';
}
Or a template based one:
$query = $DB_site->query("SELECT fieldX FROM userfield");
while($array=$DB_site->fetch_array($query))
{
$webcamurl = $array['fieldX'];
// Declare anything else here
eval('$variable = "' . fetch_template('template_name') . '";');
}
For the second one, you'd create a template and inlclude anything you want repeated inside of it (could be rows of a table (including the $webcamurl)). Then just insert $variable into your main template, and it will repeat the contents.
Edit: by the way, if your php file isn't associated with vBulletin (doesn't include global.php) you have to use mysql_query instead of $DB_site->query and mysql_fetch_array instead of DB_site->fetch_array. Also, if this is the case, you can't use templates, obviously. :)
thanks for the info. :)
Yerah it's going to include global.php. so it will work, but thanks for the info. :)
filburt1
03-17-2005, 03:01 AM
If the user is logged in, just use $bbuserinfo['fieldn'] in your PHP, just as you woul d in a template.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.