ajax request php file and load mysql into listbox

Get help using Construct 2

Post » Wed Jan 02, 2013 3:24 am

Hi Guys,

I am trying to fix my problem but still my script is not working, I hope someone can help me fix this issue.

What I am trying to do is I request php file to get information from my database. And the return value of my php will load into the listbox.

The php file is working correctly but the return to listbox is not correct value, because the return data is only on the first data of my database.

Heres my files.

(IMAGE)This is my php return.
https://www.dropbox.com/sh/097xa30dcgmnlzt/cuv9YRl7Ky?m#f:php.png

(IMAGE)This is my listbox return.
https://www.dropbox.com/sh/097xa30dcgmnlzt/cuv9YRl7Ky?m#f:result.png

(IMAGE)This is my event.
https://www.dropbox.com/sh/097xa30dcgmnlzt/cuv9YRl7Ky?m#f:listbox.png

(CAPX)This is my CAPX.
https://www.dropbox.com/sh/097xa30dcgmnlzt/sfix2gCikH/listbox_problem.capx

(PHP file)This is my php file.
https://www.dropbox.com/sh/097xa30dcgmnlzt/QipTOHZEib/user_list.php

(SQL FILE)And this is my sql file.
https://www.dropbox.com/sh/097xa30dcgmnlzt/Y_WyW8m2Va/user.sql

I badly need to fix this issue. Please guys help me fix this issue.aragon2013-01-02 03:26:20
B
16
S
2
Posts: 21
Reputation: 869

Post » Wed Jan 02, 2013 10:20 am

Change
tokenAt(AJAX.LastData, ComboBoxListBox.IID, "|")
to
tokenAt(AJAX.LastData, loopindex, "|")

The combo box IID will always be the same value - 0, so the tokenAt expression only returns the first token.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Wed Jan 02, 2013 10:48 am

@ramones,

Thank you so much for your response. Its very helpful.
B
16
S
2
Posts: 21
Reputation: 869

Post » Thu Jan 03, 2013 3:24 am

@ramones,

I have a followup question, Is it possible to display the ID from database when I click the data?

For example, the value number 1 is test01. and when I click test01 the textbox on username will display the ID from database which is ex. ID : "1005". Is it possible?
B
16
S
2
Posts: 21
Reputation: 869

Post » Thu Jan 03, 2013 4:09 am

<?php

$db = "database";//Your database name
$dbu = "root";//Your database username
$dbp = "";//Your database users' password
$host = "localhost";//MySQL server - usually localhost

$dblink = mysql_connect($host,$dbu,$dbp);
$seldb = mysql_select_db($db);

if(isset($_GET['username'])){

     //Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
     $username = strip_tags(mysql_real_escape_string($_GET['username']));
    $query = "select * from user where username='$username'";
    $result = mysql_query($query) or die("User does not exist") ;
    $result2=mysql_fetch_array($result);
    if($result2)
    {
       session_start();
       $_SESSION['username']=$username;
       echo "$result2[id]";
    }
    else
    {
       print 'Wrong username or password.';
    }
    }
else
{

echo "No data input to page.";

}

?>droptank212013-01-03 04:12:52
B
22
S
9
G
3
Posts: 203
Reputation: 3,647

Post » Fri Jan 11, 2013 10:19 am

@ramones and @droptank21,

Do you have Idea why the loop inside my listbox is infinite looping?
After my data load it will load again, it an infinite loop.

this is my events:
https://www.dropbox.com/sh/k354731q80r8z7x/x1DcnU9LL6#f:listbox_Events.PNG

This is the result in browser:
https://www.dropbox.com/sh/k354731q80r8z7x/x1DcnU9LL6#f:listbox1.PNG

There is a problem on my loop and I can't find which of my events or actions have problem.aragon2013-01-11 10:57:07
B
16
S
2
Posts: 21
Reputation: 869

Post » Fri Jan 11, 2013 5:56 pm

The event that does the "StudentList" AJAX request seems to be run every tick unless it's a subevent of something else? Probably needs a trigger once.

The student list repeat loop should be a subevent of AJAX: On "StudentList" completed.

And the other events in the "List of Students" group probably shouldn't be there because you deactivate the group the first time you use it so those events will likely never run.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Jan 13, 2013 5:23 pm

@ramones,

I am confuse on the script, its not working.
Can you please take a look on my file?

https://www.dropbox.com/sh/889fzk5wg7ck5yk/rp0djc80_E
B
16
S
2
Posts: 21
Reputation: 869

Post » Sun Jan 13, 2013 7:42 pm

Here you go: listbox_problem.capx
I added some comments to the capx.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Jan 14, 2013 2:50 am

@ramones,

Thank you so much. Its working now.
C2 is so powerful.
B
16
S
2
Posts: 21
Reputation: 869

Next

Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, marekmk and 1 guest