FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Separating contents of MySQL row and put them in variables?





deedee
Hey Frihosters!

Scroll down for the question: Separating contents of a MySQL row and put them in variables!

I've got a technical question about Flash. I wanna integrate PHP/MySQL with Flash (on a phpBB-forum). But the question is: How?

I tried a few things but this is a special case:

In a MySQL database I've got a table "phpbb_users" with content "user_items". "user_items" differences per user, and it contains names of items starting with a ß and ending with a Þ (so:ßitem1Þßitem1Þßitem2Þ).
In the folder "shop/images" on my server exists a file with the item name with the extension jpg, png or gif.

This is the PHP-code to show this all:

Code:

<?php

define('IN_PHPBB', true);
$phpbb_root_path = '.././';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.' . $phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//


//Start getting MySQL-data
{
   $sql = "select * from " . USERS_TABLE . " where user_id='{$userdata['user_id']}'";
   if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info on Inventory Page'); }
   $row = mysql_fetch_array($result);
   if (!isset($row['username'])) { message_die(GENERAL_MESSAGE, 'No Such User!'); }
   else
   {
      $itempurge = str_replace("?", "", $row['user_items']);
      $itemarray = explode('?',$itempurge);
      $itemcount = count($itemarray);
      $user_items = '<br>';
           for ($xe = 0; $xe < $itemcount; $xe++)
      {
         if ($itemarray[$xe] != NULL)
         {
            if ((${$itemarray[$xe]} != set) && ($board_config['viewinventory'] != normal)) { $useritemamount = substr_count($row['user_items'], "?".$itemarray[$xe]."?"); }
            if (((${$itemarray[$xe]} != set) && ($board_config['viewinventory'] == grouped)) || ($board_config['viewinventory'] == normal))
            {
               if (file_exists(".././shop/images/$itemarray[$xe].jpg")) { $itemfilext = "jpg"; }
               elseif (file_exists(".././shop/images/$itemarray[$xe].png")) { $itemfilext = "png"; }
               else { $itemfilext = 'gif'; }
               $playeritems .= '<tr><td class="row2"><span class="gensmall"><img src=".././shop/images/'.$itemarray[$xe].'.'.$itemfilext.'" title="'.$itemarray[$xe].'" alt="'.$itemarray[$xe].'"></span></td>';
            }
            if ((${$itemarray[$xe]} != "set") && ($board_config['viewinventory'] != "normal")) { $playeritems .= '<td class="row2"><span class="gensmall">'.$useritemamount.'</span></td></tr>'; ${$itemarray[$xe]} = "set"; }
            else { $playeritems .= '</tr>'; }
         }
      }
   }

}

//Show Items
echo($playeritems);

?>


If you go there (and you are logged in) you will see the picture of a item with the amount after it, and, if it is available, another item also with the amount.

Now I want these items in Flash one by one as a Symbol, so I can Actionscript them.
If you posses 2 of 1 item I also want that Item twice in Flash.
I wanna Actionscript them like this:

Code:

on(press) {
  startDrag(this,false);
}
on(release) {
  stopDrag();
}


All I want is dragging, all apart from eachother Wink

Does anyone knows a solution or a clue?

I'll be very, very Happy with it!
Sappho
Hmm maybe i didnt understand it correctly but if i did here is what u r after.

Parse each object:
Code:

this.createEmptyMovieClip("item_name", item_depth);

this.item_name.onPress = function() {
   this.startDrag(false);
}

this.item_name.onRelease = function() {
   this.stopDrag();
}


As u already know this refers relatively to the current object, so put it inside any movieclip u want. It just basically creates empty movie clip for each object and assign custom onPress and onRelease functions to it (dont forget that u can even have different functions for different objects Smile ), of course u need the parser which u prolly already have. And dont forget that u need to have unique depth(item_depth) and instance name (item_name) for each object.
deedee
Sappho wrote:
Hmm maybe i didnt understand it correctly but if i did here is what u r after.

Parse each object:
Code:

this.createEmptyMovieClip("item_name", item_depth);

this.item_name.onPress = function() {
   this.startDrag(false);
}

this.item_name.onRelease = function() {
   this.stopDrag();
}


As u already know this refers relatively to the current object, so put it inside any movieclip u want. It just basically creates empty movie clip for each object and assign custom onPress and onRelease functions to it (dont forget that u can even have different functions for different objects Smile ), of course u need the parser which u prolly already have. And dont forget that u need to have unique depth(item_depth) and instance name (item_name) for each object.


hmmm... But how do I get the right Items per user (which are in MySQL) in my Flash then?
Each user has different items...
Sappho
deedee wrote:
hmmm... But how do I get the right Items per user (which are in MySQL) in my Flash then?
Each user has different items...


Thats all PHPs work, i made a small forum using Flash+PHP+MySQL and its rather simple, first u need to get authrization info about user in Flash then send it to PHP that will check it with DB if its correct, if yes send it back to Flash which will keep the info (prolly username or ID) and then later if u want to query anything from DB just send request to PHP again along with the stored ID so the PHP script will know which items to fetch and send back to Flash. So there u are now u got all ur items u wanted through loadVars in ur flash and u can parse em (creating movieclip for each as i posted above).

I hope thats what u wanted. Wink
deedee
I'm very sorry but it's not very clear to me...
I think you are right but how must I code that all?

It's very hard to understand...
Sappho
I dont know what do u really want? The whole board architecture and Flash<->PHP<->MySQL implementation? Its rather long and really too much to write here. As i see it u did try to get much more than u can handle, try something simplier or check out flash portals and forums like www.flashkit.com or www.ultrashock.com

Anyway the forum i mentioned worked like this, more explanatory:

Flash asks for authorization info as soon as it starts
->
sends it to PHP script through LoadVars.sendAndLoad method (u prolly know how this works since u work with Flash<->PHP communication)
->
now we have PHP script called from flash loaded with authorization info (login/pass prolly), connect to database and check if the values correct (simple query for login and check if the pass match the one we got) if it is correct send YES back to Flash or NO in that matter.
->
This YES/NO will come to Flash from within the same call of LoadVars since we will used the sendAndLoad method, so we can either ask user to retype the authorization if we got a NO or proceed further if we got YES (dont forget that we still have the login/pass info safely within flash)
->
now somewhere in our flash we need to list all the items available to current user, so we again use LoadVars and send login info to another PHP script
->
here we got ourselves another PHP script called and loaded with login info, so we will took this login and query our table with items for those that are connected to our user and send em back to flash
->
we got em in flash so we can parse em HURRAAYY

I hope thats it. Smile
deedee
Yes, but I don't care for the login stuff...

All that really matters is:

How to code the PHP and Flash so I can get the Items stored in MySQL, and load them in Flash. These Items varies per user as you know.

I'm sorry for bothering you.
Sappho
But u need the login, how else will u identify the user and query which items belong to him?
deedee
If you go to the page where I embedded the Flash file there is a piece of line that redirects you to the login page if you're not logged in already!

The user_id and user_name are stored.

I hope it's clear for you now.

EDIT:

New Question:

In PHP I accessed the MySQL Database. I imported into PHP "$row['user_items']"

This is what I do:

Code:
$sql = "select * from " . USERS_TABLE . " where user_id='{$userdata['user_id']}'";
   if ( !($result = $db->sql_query($sql)) ) { message_die(GENERAL_MESSAGE, 'Fatal Error Getting User Info on Inventory Page'); }
   $row = mysql_fetch_array($result);
   if (!isset($row['username'])) { message_die(GENERAL_MESSAGE, 'No Such User!'); }
   else
   {
      $itempurge = str_replace("***Here stands a rare letter***", "<br>", $row['user_items']);
      $itemarray = str_replace('***Also here a rare letter***', "", $itempurge);
   }


So what I did is I asked for the user_items, which are stored in the format: ßitem1Þßitem1Þßitem2Þ

I first replaced the Þ (is it a Greek ro?) with a <br>.
Now I got as output in PHP:
Code:

ßitem1
ßitem1
ßitem2

Next, I replaced the ß (is it a Greek beta?) with nothing. My output is:
Code:

item1
item1
item2


Now, how can I program PHP so that I can use:
Code:

print "VarItem1=$item1";
print "VarItem2=$item2";
print "VarItem3=$item3";

I can import VarItemX into flash, but how do I get each item separate into $itemX??? (So first item in $item1, second in $item2 etc, up to 100 or more)

Maybe something like:
Code:

$item1="*LINE1?*";
$item2="*LINE2?*";
$item3="*LINE3?*";


Hope you can help me!
JustaMin
An array would be the simplest way of doing this Smile
deedee
JustaMin wrote:
An array would be the simplest way of doing this Smile


But how precisely?

How can I assign 1 item per variable?
n0xvb
deedee wrote:
JustaMin wrote:
An array would be the simplest way of doing this Smile


But how precisely?

How can I assign 1 item per variable?


You can try using something like this, it will read each row from your database and assign the value into an array then the foreach loop will display each element of the array:
Code:
<?php

//
//        Get each instance of a row in the db and place in an array
//        The database connection must be started first!
//

$table_name = 'USERS_TABLE';
$query = mysql_query("SELECT * FROM '$table_name'");

while($data = mysql_fetch_array($query))
{
$item[] = $data['field_name'];
}



//
//   Display all items in the array
//

foreach($item as $value)
{
print "Item: $value";
}

?>
n0xvb
You could also do it this way with a different type of looping:
Code:

<?php

//
//        Get each instance of a row in the db and place in an array
//        The database connection must be started first!
//

$count = 0;
$table_name = 'USERS_TABLE';
$query = mysql_query("SELECT * FROM '$table_name'");

while($data = mysql_fetch_array($query))
{
$item[++$count] = $data['field_name'];
}


//
//   Display all items in the array
//

for ($i = 1;$i <= $count; $i++)
{
print "Item $i: $item[$i]";
}

?>
deedee
{ Please use the "Edit" button to avoid double-post! }

I shall try when I have the time...

Please stand by Wink
Related topics
How do we install Invision Board manually through cpanel?
I'm 15 yo and heres my site, hope you like it!
[man]Servidor Web Personal (Tutorial)
mysql_real_escape_string question
yantrapark.com
Is a site like this could be popular?
PHP Member System (using FOPEN)..
Seach MySQl for muiltipe variables
Programs integrated to the system
admin page troubles
mail problems
Browser Close User Offline
protect my administration pages.
adsense question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.