PDA

View Full Version : need help with sendAndLoad problem


fifin04
02-16-2006, 02:16 AM
Hi..there...

Okay I just need help with sendAndLoad ...because when php pass the variable it keeps trace undefined...so I really need help u guys to check if my code are wrong...atr least tell me where is the my mistake...

here's are the AS I'm using..


var cbdt = new LoadVars();
var getdt = new LoadVars();
getdt.onLoad = loadthumb;

function searchdt(dtSel){
cbdt.dataType = dtSel;
//dtSel -->> I pas this value from comboBox into this function
//for (var prop in cbdt) {
// trace("About to send "+prop+" as: "+cbdt[prop]);
//}
cbdt.sendAndLoad("http://localhost/multiupload/getimage.php?ck="+new Date().getTime(),getdt);

}


var col:Number = 3;
var typeArr:Array = [];
function loadthumb(){
errortext.text = this.items;
if(success){
//trace(this.items);
}else{

//trace(this.messsage);
errortext.text = this.messsage;
}
}
//////////////////////////////////////



and this is for php



<?
$dbhost = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "ecard";

$db = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname, $db) or die("ERROR: Cannot connect to the database");

$typedt=$_POST['dataType'];

if (!get_magic_quotes_gpc()) {
foreach($_POST as $key=>$value) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}



$query = "SELECT type FROM img WHERE type = '$typedt'";
$result = mysql_query($query);
$row = mysql_num_rows($result);

if (!$row == 0){
echo "&items=$row";
//echo $row;

for ($i=0; $i < $row; $i++) {
$dt = mysql_fetch_array($result );

echo "&type$i=". $dt['type']."";

}
echo "&end";
echo ("&message=yes you got it");

}else{
echo ("&message=No elements has found");

}

?>





So really nee dhelp with it..

tq in advanced

Flash Gordon
02-16-2006, 03:36 AM
cbdt.sendAndLoad("http://localhost/multiupload/getimage.php?ck="+new Date().getTime(),getdt);

Your not setting the object to load into and the POST or GET

e.g.

LV.sendAndLoad("file.php", LV, "POST");

fifin04
02-16-2006, 05:35 AM
cbdt.sendAndLoad("http://localhost/multiupload/getimage.php?ck="+new Date().getTime(),getdt);

Your not setting the object to load into and the POST or GET

e.g.

LV.sendAndLoad("file.php", LV, "POST");

Hi..Flash Gordon..thanks for the reply...

Okay...okay..I just add as ur per suggest using "POST" but it still trace undefined..

cbdt.sendAndLoad("http://localhost/multiupload/getimage.php?ck="+new Date().getTime(),getdt,"POST");

and regarding the object to load into I think I already have setup...is this what u mean...


var getdt = new LoadVars();
getdt.onLoad = loadthumb;

/////////////////////////

var col:Number = 3;
var typeArr:Array = [];
function loadthumb(){
errortext.text = this.items;
if(success){
//trace(this.messsage);
}else{

//trace(this.messsage);
errortext.text = this.messsage;
}
}


So..I totally lost now...

Flash Gordon
02-16-2006, 05:37 AM
alright, the best way to debug is to use

getURL("phpfile.php", "_blank", "POST");

Does PHP actually echo the correct variables?

fifin04
02-16-2006, 05:49 AM
alright, the best way to debug is to use

getURL("phpfile.php", "_blank", "POST");

Does PHP actually echo the correct variables?

Emm..it's keep return "&message=No elements has found "

Okay mate u can check my file ..I attach herein..

tq for ur time..

Flash Gordon
02-16-2006, 05:54 AM
Well, not really :p

I'm not too familar with how you are querying the database. This is how I normally do it.

$query = "SELECT * FROM $table";
$myQuery = mysql_query($query);
//-------manage data
while($record = mysql_fetch_array($myQuery)) {
$date[] = $record['date'];
$event[] = $record['event'];
$website[] = $record['website'];
$time[] = $record['time'];
}

Flash Gordon
02-16-2006, 05:57 AM
but for your code, start here:



if (!get_magic_quotes_gpc()) {
foreach($_POST as $key=>$value) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}



$query = "SELECT type FROM img WHERE type = '$typedt'";
$result = mysql_query($query);
$row = mysql_num_rows($result);

print_r($row);

exit();

?>

what is the output?

Flash Gordon
02-16-2006, 05:59 AM
for ($i=0; $i < $row; $i++) {

that looks wrong to me too. SHould be:

for ($i=0; $i < count($row); $i++) { or something like that.

fifin04
02-16-2006, 06:01 AM
Well, not really :p

I'm not too familar with how you are querying the database. This is how I normally do it.

$query = "SELECT * FROM $table";
$myQuery = mysql_query($query);
//-------manage data
while($record = mysql_fetch_array($myQuery)) {
$date[] = $record['date'];
$event[] = $record['event'];
$website[] = $record['website'];
$time[] = $record['time'];
}

Okay if I'm using ur example query ..well in flash then How I would do to organise the data being load into..sorry for being such jerk?..but I really confuse..because normaly it can load the data very clean..and no problem..

can I just use this..

echo "&type =". $record['type']."";

Flash Gordon
02-16-2006, 06:04 AM
Flash doesn't care how you query the database. As long as something gets output to the browser, it is all good.

You apparently have errors in you PHP hence the if(!row == 0) isn't exucuting. Just fix the errors (whatever they are, like I said I don't do it like that) and you'll be fine.

fifin04
02-16-2006, 06:41 AM
Flash doesn't care how you query the database. As long as something gets output to the browser, it is all good.

You apparently have errors in you PHP hence the if(!row == 0) isn't exucuting. Just fix the errors (whatever they are, like I said I don't do it like that) and you'll be fine.

hey Flash Gordon..

I think I so close to fix it... ok I just change this in php


$result = mysql_query('SELECT type FROM img WHERE type = "'.$_POST['dataType'].'"') or mysql_error();


while($row = mysql_fetch_array($result)){

echo "&items".$row['filename'];


}


and in flash I chage this



var getdt = new LoadVars();
getdt.onLoad = function(success){
//trace(this.items);
if(success){
trace(this.items);
//errortext.text = this.items;
}else{

}


}


but when I trace this... trace(this.items); it return empty...so where exactly my mistake..mate...

tq again

Flash Gordon
02-16-2006, 06:47 AM
$z=0
while($row = mysql_fetch_array($result)){

echo "&items$z".$row['filename'];
$z++;
}


getdt.onLoad = function(success){
for (i in this) {
trace(LV.i + " = " + i);
}
}

fifin04
02-16-2006, 08:11 AM
I really don't have idea why it's still keep tracing undefined...

it seem's the php page not receive my post variable...I think...

Flash Gordon
02-16-2006, 03:23 PM
You're still using getURL :p

It doesn't send anything back.

fifin04
02-17-2006, 08:49 AM
You're still using getURL :p

It doesn't send anything back.

Hey flash Gordon....

I'm not using getURL....??just using sendAndLoad..but just got fix it..only my problem now is in flash...hope u can take look ...My attempt is to attach thumb based on how many dt get return in flash...so far it's okay only..when i choose another value from combobox..it will not eliminate the previous attach thumb...and also I try to attach gradually one by one.with bounce effect using Laco's..but it's seem not working at all..u can see my AS here..


function searchdt(dtSel){
cbdt.dataType = dtSel;
//for (var prop in cbdt) {
// trace("About to send "+prop+" as: "+cbdt[prop]);
//}
//just success send dt
cbdt.sendAndLoad("http://localhost/multiupload/getimage.php",getdt,"POST");
}

var i:Number = 0;
var col:Number = 3;
var spacing:Number = 10;
createEmptyMovieClip("paper", 99);
paper._x = 200;
paper._y = 30;
var elasticSpeed:Number = .7;
var makeBoxesSpeed:Number = 100;

function loadthumb(success:Boolean){
if(success){
//paper.removeMovieClip();
// id = setInterval( test, makeBoxesSpeed);
//okay here I pass to function test
test(this.items);
trace(this.message);

}else{
//paper.removeMovieClip();
trace("nothing found");
trace(this.message);
}
}

function test(a){
//okay here i doing some tracing and it's okay it return the rite dt and the count as well
trace(a);
for (var i = 0; i<a; i++) {
//if(i<a){
// trace(i);
//input1 = this["filename"+i];
//trace(input1);
//okay here I just attempt to attch gradually one by one and with bounce effect but it's seem not working at all...

var mythumb = paper.attachMovie("box", "box"+i, i);
mythumb._x = (i%col)*(mythumb._width+spacing);
mythumb._y = Math.floor(i/col)*(mythumb._height+spacing);
//mythumb.bounceMe();
//i++;
//} else{

//clearInterval(id);
//}
}
}

MovieClip.prototype.bounceMe = function() {
this.scaleTo(100, elasticSpeed, "easeOutElastic");
};/*
id = setInterval(loadthumb, makeBoxesSpeed);
*/




Hope u can help me out with this Flashgordon..at least tell me which part is wrong...


tq again...

fifin04
02-18-2006, 08:39 AM
Hi...

Okay Flashgordon I got manage to attach thumb mc one by one based on amount get from php...okay to make easy for u I just simplify this in flash only..forget about the php things for moment..Okay ...just now I didn't have idea how to removeMovieclip previous attach..
I mean eg;

for btn0 will attach 3 mc,btn1 will attach 5 mc, btn2 will attach 10 mc..so How to remove movieclip for 10 attach mc if I just pressing btn0-->for attaching 3 mc only...
here's the code

#include "lmc_tween.as"

var i:Number = 0;
var col:Number = 4;
var spacing:Number = 10;
var makeBoxesSpeed:Number = 100;
var elasticSpeed:Number = .7;
this.createEmptyMovieClip("container", 999);
container._x = 100;
container._y = 100;

function makeBoxes(boxes) {

trace(boxes);
if (i<boxes) {
var makeMe = container.attachMovie("box", "box"+i, i);
makeMe._x = (i%col)*(makeMe._width+spacing);
makeMe._y = Math.floor(i/col)*(makeMe._height+spacing);
makeMe._xscale = 0;
makeMe._yscale = 0;
makeMe.bounceMe();
i++;
} else {
clearInterval(id);
//container.removeMovieClip();
}


//}
}
MovieClip.prototype.bounceMe = function() {
this.scaleTo(100, elasticSpeed, "easeOutElastic");
};

//////////////////////////////
valueArr = ["2","3","10"];

for(j=0;j<3;j++){
this["btn"+j].ivar = j;
this["btn"+j].onPress = function(){
id = setInterval(makeBoxes, makeBoxesSpeed,valueArr[this.ivar]);
}

}




So I really need help with it...after for couple of try and error..

tq again for ur time..