Display the value in prompt message using Javascript and PHP -
i'm newbie in using of javascript php. need me solve problem.
scenario:
i have table name "tbldata".
in database, below data tbldata.
fldbldgname fldplaylist bldg 1 playlist1 bldg 1 playlist2 bldg 1 playlist3 bldg 2 playlist4
i have form display data of fldbldgname checkbox. when check checkbox of bldg 1 click button name "view playlist" display fldplaylist of bldg1 using javascript or prompt message.
for summary:
i want display data of bldg1 or other bldg in prompt message using javascript okay button only. there way this? search google can't find answer problem.
thanks in advance.
there two ways this.
1. generating javascript on server php. small example:
php (pseudo-code)
$sql = // ... (your sql query); $list = // ... (your result objects sql); // build html of received items want show $html = '<div id="playlists">'; foreach(listitem in list) { $html .= '<div onclick="alert(\''.listitem->getbldgdata().'\'">'.listitem->gettitle().'</div>'; } $html .= '</div>';
this possibility simple has load need before displaying on client side. take resources if list grows , list potentially listitems data. not recommence use style.
2. generate list of playlists , on each click on specific playlist, load bldg ajax request server.
php(pseudo-code) site
$sql = // ... (your sql query); $list = // ... (your result objects sql); // build html of received items want show $html = '<div id="playlists">'; foreach(listitem in list) { $html .= '<div onclick="getbldgdata(\''.listitem->getid().'\')">'.listitem->gettitle().'</div>'; } $html .= '</div>';
javascript/ajax (pseudo-code)
include jquery library better ajax call handling.
function getbldgdata(id){ $.ajax("yoururl/pathto/phpwebservice", { data: id }) .success(function(data){ // received bldgdata webservice (json) }) .error(function(err){ // message box error alert(err); }); };
php(pseudo-code) webservice
$id = $_get['data']; $sql = ... // sql statement bldg data playlist (id); $bldgdata = ... // received data; $formatbldgdataasjson = ... // transform data should proceeded on client side. echo $formatbldgdataasjson;
i recommence use second ajax version. needed data fetched database.
sorry pseudo code if completly write down in correct syntax take long write while lunch ;)
Comments
Post a Comment