Advertisement

05.11.2008 at 12:29PM PDT, ID: 23392998
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Datagrid - MYSQL/PHP Alphabetic filter

Asked by digitalPencil in Macromedia Flash, PHP and Databases, MySQL Server

Tags: , , ,

I currently have a flash file which looks up a MYSQL db via PHP and using loadVars, populates a datagrid with the table contents. This works great but i'm now wanting to get filter the datagrid contents alphabetically, i.e. only display records beginning with 'A'

I am attempting to do this by sending a variable 'A' to a PHP script, which then queries the MYSQL db and gets the data back into flash, replacing the contents of the datagrid with records beginning with 'A'. However this is not working..

My AS code is attached to this post and the PHP script is as follows:
<?
/*
   select_alpha_pass2.php: Retrieves character variable from flash and queries mysql for all records beginning with letter
   
   errorcode:
      0: successful select
      1: can't connect to server
      2: can't connect to database
      3: can't run query
*/

//  fill this in with the right data for your server/database config
$server = "mysql1.100ws.com";
$username = "davgra0_videotab";
$password = "85375975";
$database = "davgra0_videotab";

//  mysql_connect: Open a connection to a MySQL Server
//  Returns a MySQL link identifier on success, or FALSE on failure.
if (!mysql_connect($server, $username, $password)) {
   $r_string = '&errorcode=1&';
       
} elseif (!mysql_select_db($database)) {
   $r_string = '&errorcode=2&';
         
} else {
   $qr = mysql_query("SELECT * FROM videotab WHERE artist LIKE '$receiver_lv%' ORDER BY artist ASC;");
   if (!qr || mysql_num_rows($qr)==0) {
      $r_string = '&errorcode=3&msg='.mysql_error().'&';
   } else {
      $r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
      $i = 0;
      while ($row = mysql_fetch_assoc ($qr)) {
         while (list ($key, $val) = each ($row)) {
            $r_string .= '&' . $key . $i . '=' . stripslashes($val);
         }
         $i++;
      }
      // add extra & to prevent returning extra chars at the end
      $r_string .='&';
   }
}
echo $r_string;
?>

A live example can be found here:
http://davgra0.100webspace.net/tabsClipAlpha.html

You can access all my files and mysql db with the following login etc.

Webhost URL: www.100webspace.net
username: davgra0
password: 85375975

MYSQL DB name: davgra0_videotab
DB username: davgra0_videotab
DB password: 85375975
Table name: videotab

---- FLV/SWF/PHP Scripts:
Goto 'Site Management'>'File Manager'

Path for SWF: davgra0.100webspace.net/tabsClipAlpha.swf
Path for FLA: davgra0.100webspace.net/tabsCliplAlphaFLA.zip
Path for PHP Scripts: davgra0.100webspace.net/scripts/
- getlivetab.php
- select_alpha_pass2.php



I imagine this is a simple problem but I can't for the life of me figure it out and it's really quite urgent! If anyone can fix the FLA or has any ideas, your advice would be greatly appreciated.

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
// for select query
var select_lv:LoadVars = new LoadVars ();
var errorMsgs:Array = ["", "Couldn't connect to server", "Couldn't connect to database", "Error running query", "First four entries may not be deleted"];
// create a string to show where to access the PHP script
var filepath:String;
// string to store video filepath
var videofilepath:String;
// create an array to be the dataprovider for the datagrid
var tabInfo:Array = [];
var tabAlpha:Array = [];
// create an object to listen for clicks on datagrid headers to do correct sort
var headerListener:Object = {};
headerListener.headerRelease = function (event:Object) {
	switch (event.columnIndex) {
	case 0 :
		if (tab_dg.getColumnAt (0).sortedUp) {
			tab_dg.sortItemsBy (tab_dg.columnNames[0], Array.CASEINSENSITIVE | Array.DESCENDING);
		} else {
			tab_dg.sortItemsBy (tab_dg.columnNames[0], Array.CASEINSENSITIVE);
		}
		tab_dg.getColumnAt (0).sortedUp = !tab_dg.getColumnAt (0).sortedUp;
		break;
	case 1 :
		if (tab_dg.getColumnAt (1).sortedUp) {
			tab_dg.sortItemsBy (tab_dg.columnNames[1], Array.NUMERIC | Array.DESCENDING);
		} else {
			tab_dg.sortItemsBy (tab_dg.columnNames[1], Array.NUMERIC);
		}
		tab_dg.getColumnAt (1).sortedUp = !tab_dg.getColumnAt (1).sortedUp;
		break;
	}
};
 
// script filepath
if (_url.indexOf ("http") != 0) {
	filepath = "http://davgra0.100webspace.net/scripts/";
} else {
	filepath = "../scripts/";
}
// video/tab file path
videofilepath = "http://localhost:8888/flv/";
// limit fields to max characters allowed by database
artist_ti.maxChars = 50;
song_ti.maxChars = 10;
 
// tab_dg changeListener
changeListener = new Object ();
changeListener.change = function (evt_obj:Object) {
	 textholder.tab_txt.text = "test";
	 var lv:LoadVars = new LoadVars();
	 lv.onData = function(thetext:String) {
		 textholder.tab_txt.text = thetext;
		 bufferClip._visible = true;
		 bufferClipCover._visible = false;
		 }
// load flv file
	ns.play(videofilepath + tabInfo[evt_obj.target.selectedIndex].flv);
// load tab file
lv.load(videofilepath + tabInfo[evt_obj.target.selectedIndex].tab);
}
 
tab_dg.addEventListener ("change", changeListener);
 
// load database
select_lv.onLoad = function (ok:Boolean) {
	if (ok) {
		if (this.errorcode == "0") {
			for (var i:Number = 0; i < this.n; i++) {
				tabInfo.push ({record:this["id" + i], artist:this["artist" + i], rating:Number (this["rating" + i]), song:this["song" + i], flv:this["flv" + i], tab:this["tab" + i]});
			}
			// only display Artist, Song, and Rating (not record id, flvname, tabname)
			tab_dg.columnNames = ["artist", "song", "rating"];
			// set formatting of artist column
			tab_dg.getColumnAt (0).width = 95;
			tab_dg.sort
			// trap header click event to sort case-insensitive on this field
			tab_dg.getColumnAt (0).sortOnHeaderRelease = false;
			// this property will keep track of whether sort is ascending or descending
			tab_dg.getColumnAt (0).sortedUp = false;
			tab_dg.getColumnAt (0).headerText = "Artist";
			// set formatting of score column
			tab_dg.getColumnAt (1).width = 95;
			// trap header click event to sort numerically
			tab_dg.getColumnAt (1).sortOnHeaderRelease = false;
			tab_dg.getColumnAt (1).sortedUp = false;
			tab_dg.getColumnAt (1).headerText = "Song";
			// set formatting of date column
			// auto-sort will work fine for this column
			tab_dg.getColumnAt (2).width = 70;
			tab_dg.getColumnAt (2).headerText = "Rating";
			// set dataProvider for datagrid
			tab_dg.dataProvider = tabInfo;
			// execute headerRelease function for correct sort when user clicks a header
			tab_dg.addEventListener ("headerRelease", headerListener);
			dbloaderMC._visible = false;
			panel._visible = true;
			msg_ta.text = "Select an item from the list to loac video.";
		} else {
			// show kind of error
			msg_ta.text = errorMsgs[Number (this.errorcode)];
			// if query error, show mysql_error
			if (this.errorcode == "3") {
				msg_ta.text += ": " + this.msg;
			}
		}
	} else {
		// if loadvars failed (eg, if script not found)
		msg_ta.text = "Flash-database select operation failed";
	}
};
dbloaderMC._visible = true;
msg_ta.text = "Getting tabs from database...";
select_lv.sendAndLoad (filepath + "getlivetab.php", select_lv, "POST");
 
 
 
// ----- ALPHA -------
 
// load records beginning with 'a'
      
var sender_lv:LoadVars = new LoadVars();
sender_lv.variableToSend = 'A';
var reciever_lv = new LoadVars();
receiver_lv.onLoad = function (ok:Boolean) {
     if (ok) {
          if (this.errorcode == "0") {
               for (var i:Number = 0; i < this.n; i++) {
                    tabInfo.push ({record:this["id" + i], artist:this["artist" + i], rating:Number (this["rating" + i]), song:this["song" + i], flv:this["flv" + i], tab:this["tab" + i]});
               }
               // set dataProvider for datagrid
               tab_dg.dataProvider = tabInfo;
               // execute headerRelease function for correct sort when user clicks a header
               tab_dg.addEventListener ("headerRelease", headerListener);
               msg_ta.text = "Select an item from the list to loac video.";
          } else {
               // show kind of error
               msg_ta.text = errorMsgs[Number (this.errorcode)];
               // if query error, show mysql_error
               if (this.errorcode == "3") {
                    msg_ta.text += ": " + this.msg;
               }
          }
     } else {
          // if loadvars failed (eg, if script not found)
          msg_ta.text = "Flash-database select operation failed";
     }
     msg_ta.text = unescape(this);
};
 
alpha_btn.onRelease = function() {
	sender_lv.sendAndLoad (filepath + "select_alpha_pass2.php", receiver_lv, "POST");
}
[+][-]05.11.2008 at 05:56PM PDT, ID: 21544125

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 05:37AM PDT, ID: 21546297

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 07:57AM PDT, ID: 21547512

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Macromedia Flash, PHP and Databases, MySQL Server
Tags: Adobe/Macromedia, Flash, CS3, AS2/PHP/MYSQL
Sign Up Now!
Solution Provided By: mmarth
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628