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 03-06-2003, 11:35 PM
matthew tucker's Avatar
matthew tucker matthew tucker is offline
 
Join Date: Nov 2002
Location: Sydney, Australia
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Foreach() problem

In admin/user.php I have inserted the following code to extract data from a custom table "memberinfo" and display using the makeinputcode() function of vbulletin.

PHP Code:
maketableheader("Memberinfo details TEST (code in: admin/user.php line 308)");
  
$myquery="SELECT * FROM memberinfo WHERE email='$user[email]'";
$myresult=$DB_site->query_first($myquery);

foreach (
$myresult as $mykey=>$pointer){

    
makeinputcode($mykey,$mykey,$myresult[$mykey]);


Problem is I get two rows for each record. What have I done wrong??
Attached Images
File Type: jpg phpprob.jpg (5.9 KB, 0 views)
Reply With Quote
  #2  
Old 03-06-2003, 11:50 PM
MUG MUG is offline
 
Join Date: Apr 2002
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's the way mysql_fetch_array() works - it returns both a numerical and associative index for each column unless specified otherwise. You can change that block of code to:
PHP Code:
maketableheader("Memberinfo details TEST (code in: admin/user.php line 308)");
$myquery=$DB_site->query("SELECT * FROM memberinfo WHERE email='$user[email]'");
$myresult mysql_fetch_array($myqueryMYSQL_NUM);

mysql_free_result($myquery);

foreach (
$myresult as $mykey=>$pointer){
  
makeinputcode($mykey,$mykey,$myresult[$mykey]);

which should work.
Reply With Quote
  #3  
Old 03-06-2003, 11:52 PM
Sebastian's Avatar
Sebastian Sebastian is offline
 
Join Date: Oct 2002
Location: America
Posts: 488
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

add LIMIT 1 to the query.
Reply With Quote
  #4  
Old 03-06-2003, 11:53 PM
MUG MUG is offline
 
Join Date: Apr 2002
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Sebastian
add LIMIT 1 to the query.
What? That wouldn't make any difference. It's only fetching one row in the first place.
Reply With Quote
  #5  
Old 03-06-2003, 11:55 PM
Sebastian's Avatar
Sebastian Sebastian is offline
 
Join Date: Oct 2002
Location: America
Posts: 488
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

its adding more results, and he/she only want 1,. not 2,3,4,5...
or did i read the post wrong?
Reply With Quote
  #6  
Old 03-06-2003, 11:57 PM
MUG MUG is offline
 
Join Date: Apr 2002
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Sebastian
its adding more results, and he/she only want 1,. not 2,3,4,5...
or did i read the post wrong?
He's using foreach() on something returned by mysql_fetch_array() - which by default includes each column twice, unless you specify otherwise.
Reply With Quote
  #7  
Old 03-07-2003, 01:11 AM
matthew tucker's Avatar
matthew tucker matthew tucker is offline
 
Join Date: Nov 2002
Location: Sydney, Australia
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I (he!) want to step through all the fields in the array!

I started to use extract() then hard-code all the makeinputcode bits, then I though no, why not build an interface to the memberinfo table on the fly rather than hard code it.

Foreach() looked a bettersolution than while() ...

I'll try your suggestions.

I was trying to use the vB functions but now I think I'd probably be better off just using plain PHP and mySQL so I understand the code better, no? I'm a bit new to PHP, trying hard ...

Matthew
Reply With Quote
  #8  
Old 03-07-2003, 01:16 AM
matthew tucker's Avatar
matthew tucker matthew tucker is offline
 
Join Date: Nov 2002
Location: Sydney, Australia
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nope

I get

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /[path]/user.php on line 314
Reply With Quote
  #9  
Old 03-07-2003, 01:45 AM
matthew tucker's Avatar
matthew tucker matthew tucker is offline
 
Join Date: Nov 2002
Location: Sydney, Australia
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All fixed. thanks. I needed the MYSQL_ASSOC value!

Works now, thanks x 10^6

Matthew
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 03:50 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08204 seconds
  • Memory Usage 2,264KB
  • Queries Executed 12 (?)
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
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete