This topic is locked

in add_page i want to use dropdown menu to display picture in the same add_page.

2/17/2012 8:29:26 PM
PHPRunner General questions
S
siro author

Please i need help
in add_page i want to use dropdown menu to display picture in the same add_page,

only one picture works, when I select an other name the same picture show up,

I already upload the other pictures. I want to use Dynamic dropdwon menu to display picture in the same add_page.
this is the codes i used,
$sql = "SELECT Presidents FROM President";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

echo "<img width=\"95\" height=\"90\" src=\"files/".$data["Presidents"]."\">";

Sergey Kornilov admin 2/17/2012

Here is the link to sample code that can change the image based on dropdown box selection:

http://www.ahfb2000.com/webmaster_help_desk/showpost.php?p=29853&postcount=2
You need to modify this code accordingly and plug it in using Javascript API. Here is an example of adding code to dropdown box "change" event:

http://xlinesoft.com/phprunner/docs/show_dropdown_list_of_us_states.htm

S
siro author 2/18/2012

Hi admin
I already created dropdown list from lookup wizard

and I used php code snippet to display the pictures, I have 3 pictures in files.
I used this is code in php code snippet.
$sql = "SELECT Presidents FROM President";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

echo "<img width=\"95\" height=\"90\" src=\"files/".$data["Presidents"]."\">";
this the picture


this is the table.

SELECT

PresidentID,

UserID,

Haiti,

Presidents,

VotezPour,

Nom,

Photo,

InitialeParti,

Departement,

Arrondissement,

Commune,

Section/Ville,

View

FROM Presiden

C
cgphp 2/18/2012

If you want to dynamically load images from the database you need to modify your code to make an AJAX call.

S
siro author 2/18/2012



If you want to dynamically load images from the database you need to modify your code to make an AJAX call.


Hi Gile

can you show me some example about code AJAX call, and can I use the code in PHP-code-Snippet.

C
cgphp 2/19/2012

The server side code you will call with the AJAX call should be put in a external file or in the "List page: Before process" event. I will opt for the second solution:
On the Add page, near the dropdown, enter a template var like this:

{$president_photo}


In the "Before display" event of the Add page enter the following code:

$xt->assign('president_photo',"<span id='president_photo'></span>");


In the "Javascript onload" event of the President Add page enter the code to handle the change of the dropdown value:

$("#dropdown_id").change(function(e){

$.ajax({

url: "president_list.php",

data: "president="+$(this).val(),

type: "POST",

dataType: "json",

success: function(res)

{

$("span[id='president_photo']").html("<img src='"+res.photo+"' alt='President photo' />");

}

});

});


In the "List page: Before process" event of the President page:

if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{

//here extract the president photo path based on the $_POST['president'] value from the AJAX call

$rs = CustomQuery("SELECT photo FROM president_table WHERE president_id=".$_POST['president']." LIMIT 1");

$record = db_fetch_array($rs);

echo json_encode(array('photo' => $record['photo']));

exit();

}
S
siro author 2/20/2012



The server side code you will call with the AJAX call should be put in a external file or in the "List page: Before process" event. I will opt for the second solution:
On the Add page, near the dropdown, enter a template var like this:

{$president_photo}


In the "Before display" event of the Add page enter the following code:

$xt->assign('president_photo',"<span id='president_photo'></span>");


In the "Javascript onload" event of the President Add page enter the code to handle the change of the dropdown value:

$("#dropdown_id").change(function(e){

$.ajax({

url: "president_list.php",

data: "president="+$(this).val(),

type: "POST",

dataType: "json",

success: function(res)

{

$("span[id='president_photo']").html("<img src='"+res.photo+"' alt='President photo' />");

}

});

});


In the "List page: Before process" event of the President page:

if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')

{

//here extract the president photo path based on the $_POST['president'] value from the AJAX call

$rs = CustomQuery("SELECT photo FROM president_table WHERE president_id=".$_POST['president']." LIMIT 1");

$record = db_fetch_array($rs);

echo json_encode(array('photo' => $record['photo']));

exit();

}



Hi Gile

Thank you

I used this code you sent me, no picture display I dont know if I miss something,

or do i have to modify some of the code you sent me?
thanks agian

C
cgphp 2/20/2012

Change the SQL query according to your table structure.

S
siro author 2/20/2012



Change the SQL query according to your table structure.


Hi Gile

thanks again

yes i Changed the SQL query according to my table structure.

but no picture display in {president_photo}.
look at the pictures i put


C
cgphp 2/21/2012

If you can send me a demo link (as a PM if it is more comfortable), I will try to fix the error for you.

S
siro author 2/22/2012



If you can send me a demo link (as a PM if it is more comfortable), I will try to fix the error for you.


Hi Gile

How can i send the demo link to you

S
siro author 2/24/2012



http://xlinesoft.com/phprunner/docs/what_is_demoaccount.htm



Hi Gile

I have a problem to login to demo account

i have an orther table like that
this is the table.

the table name is vote
SELECT

candidatID,

UserID,

Name,

Photo,

FROM vote
Thanks

L
laonian 2/24/2012

Joel,
When you get your problem solved, do you mind sharing the final working code with us? Thanks!

S
siro author 2/24/2012



Joel,
When you get your problem solved, do you mind sharing the final working code with us? Thanks!



yes i will

Sergey Kornilov admin 2/24/2012

Joel,
you need to contact support directly in this regard. Open ticket at http://support.xlinesoft.com sending your sending your project file.

S
siro author 2/27/2012



Joel,
you need to contact support directly in this regard. Open ticket at http://support.xlinesoft.com sending your sending your project file.


Hi Gile
this is the link : for open ticket

http://xlinesoft.com/dss/support.asp?link=history&mess=ok