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 01-19-2011, 03:47 PM
sharpkiller sharpkiller is offline
 
Join Date: Aug 2009
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Reading Data

Hello,

I currently help run a video gaming clan, and am a webmaster for the website. My experience and knowledge of PHP is very limited; however I have been taught how to code in Turing, Visual Basic, Java, and Python. Our clan has an application process which requires administrators numerous to complete numerous steps. Essentially, we are looking to shrink this process down to a click of a button.

We currently use the Easy Forms mod for vB3, and I'm looking to collect information from the form that the script will then apply to their forum account (eg. their desired alias in the clan). However, Easy Forms does not store each field from the form in its own column of the MySQL table, and instead regurgitates the form fields into one single column on one single line. Ideally, I would have simply liked to have read the data straight from the "formresults" table and input the corresponding information into the "users" table, but that isn't possible here.

A back up plan was to go through the form line by line and collect the information that way, but it's all stored on a single line and uses BB code for formatting, so that again isn't possible here either. The method I've been taught in the other languages I know to tackle a string like this is to go through character by character and find the information I want and store it in a new variable. However, I haven't been able to find an information on how I might go to a certain position within a string with PHP to accomplish that method.

If anyone is able help with this, or suggest an alternative method, that'd be greatly appreciated.
Reply With Quote
  #2  
Old 01-19-2011, 06:57 PM
Beav` Beav` is offline
 
Join Date: Jun 2004
Location: London, UK
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you have an example of the string so we can see how it's formatted?
Reply With Quote
  #3  
Old 01-19-2011, 07:22 PM
sharpkiller sharpkiller is offline
 
Join Date: Aug 2009
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've actually managed to split it up and get the details I need using the explode() function. I didn't realize you could customize the parameter of where you want the function to split the string up. Here's an example anyway in case there is a more efficient method. It stores two forms of output, I used this one with the explode() function.

Quote:
a:11:{i:1;s:4:"Test";i:2;s:4:"Test";i:3;s:4:"Test" ;i:4;s:4:"Test";i:5;s:4:"Test";i:6;s:4:"Test";i:12 ;s:2:"No";i:8;s:4:"Test";i:9;s:4:"Test";i:10;s:3:" Red";i:11;s:4:"Test";}
Reply With Quote
  #4  
Old 01-19-2011, 10:20 PM
Beav` Beav` is offline
 
Join Date: Jun 2004
Location: London, UK
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's a serialized array, so ideally you should use unserialize to get the data back out again.

For example....
PHP Code:
<?
print_r(unserialize('a:11:{i:1;s:4:"Test";i:2;s:4:"Test";i:3;s:4:"Test";i:4;s:4:"Test";i:5;s:4:"Test";i:6;s:4:"Test";i:12;s:2:"No";i:8;s:4:"Test";i:9;s:4:"Test";i:10;s:3:"Red";i:11;s:4:"Test";}'));
?>
will output...
PHP Code:
Array
(
    [
1] => Test
    
[2] => Test
    
[3] => Test
    
[4] => Test
    
[5] => Test
    
[6] => Test
    
[12] => No
    
[8] => Test
    
[9] => Test
    
[10] => Red
    
[11] => Test

Reply With Quote
  #5  
Old 01-21-2011, 12:11 PM
sharpkiller sharpkiller is offline
 
Join Date: Aug 2009
Posts: 10
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cheers! Thanks for the advice. I'll definitely keep this in mind if I come across another serialized array.
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 01:38 AM.


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.03893 seconds
  • Memory Usage 2,204KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_quote
  • (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_postinfo_query
  • fetch_postinfo
  • 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