Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2007, 10:36 PM
bvondane bvondane is offline
 
Join Date: Jan 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP MYSQL Query

I am trying to write a query, am making myself nuts and could use some help...

What I want is a PHP file that; based on the userid of the person logged in, will retrieve the the content of "field7" in the table "userfield" and assign it to a variable so I can pass it to a url in an iframe...

Make sense? I hope so because my brain is fried!

Here's what I have so far:

Code:
<?php
require_once('./global.php');
$host = localhost;
$user = *****;
$dbp = *****;
$db = *****;

mysql_connect("$host", "$user", "$dbp");
mysql_select_db ("$db"); 

// $icao = mysql_query("
// SELECT field7
// FROM userfield
// WHERE userid = $vbulletin->userinfo['userid']
// ");

$icao = kcos; // <--  if I hard code it, it works
echo $icao;

?> 

<iframe width="100%" src="http://www.weathermeister.com/html/metar?idents=<? echo $icao; ?>"/>
If I hard code the $icao the file works (however the output of the file needs to be tweaked - it works in IE): http://www.wheelsup.org/testquery.php ...but I need it to be dynamic based on who is logged in...

Thanks in advance!
-Bill

Ok... I am making progress here... This seems to be working:

Code:
<?php
require_once('./global.php');

// Make a MySQL Connection
mysql_connect("localhost", "*****", "*****") or die(mysql_error());
mysql_select_db("*****") or die(mysql_error());

// Retrieve all the data from the "example" table
$query = "SELECT userid, field7 FROM userfield WHERE userid = 2";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
 
$icao = $row['field7'];

// echo $icao;

?>

<iframe width="100%" src="http://www.weathermeister.com/html/metar?idents=<? echo $icao; ?>" marginwidth="0" marginheight="0" border="0" frameborder="0"/>
However, I still need a way to replace "WHERE userid = 2" in the query to something that will automatically input the current logged in user's userid...

Also, the iframe only seems to display correctly in IE, FireFox and Opera both display HTML instead of the content...

Any ideas!??
Reply With Quote
  #2  
Old 02-08-2007, 12:30 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here:
Code:
<?php
require_once('./global.php');
$host = localhost;
$user = *****;
$dbp = *****;
$db = *****;

mysql_connect($host, $user, $dbp);
mysql_select_db($db);

$icao = mysql_query("
	SELECT field7
	FROM userfield
	WHERE userid = " . $vbulletin->userinfo['userid'] . "
");
$icao = mysql_fetch_aray($icao);


?>

<iframe width="100%" src="http://www.weathermeister.com/html/metar?idents=<?php echo $icao['field'7]; ?>"/>
If it is your vBulletin database, you can reduce it to this:
Code:
<?php

require_once('./global.php');

?>

<iframe width="100%" src="http://www.weathermeister.com/html/metar?idents=<?php echo $vbulletin->userinfo['field7']; ?>"/>
Reply With Quote
  #3  
Old 02-08-2007, 01:15 AM
bvondane bvondane is offline
 
Join Date: Jan 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cool... The second one worked perfectly...

Do you know if I can use the

Code:
$vbulletin->userinfo['field7']
in other places in vbulletin? is there a bbcode syntax for using that?

I have an rssfeed module that displays this same information that I didn't think I would be able to use... It displays the rss feed from this url:

Code:
http://www.weathermeister.com/whiskeyVictor/metar?ident=CNO
I would like the "CNO" to be pulled from the database just like above... Do you think it's possible?
Reply With Quote
  #4  
Old 02-08-2007, 02:57 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BB code is possible, but you'll have to do a plugin for it to work - they aren't parsed as you'd expect.

Where does "CNO" come from?
Reply With Quote
  #5  
Old 02-08-2007, 03:03 AM
bvondane bvondane is offline
 
Join Date: Jan 2007
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The CNO that is on that URL is hardcoded for test... it's an airport identifier...

I have a custom field in the users profile where they can put their airport identifier: field7 in userfields table

...and would like to be able to pull the data automatically
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05770 seconds
  • Memory Usage 2,200KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete