ohayo85 Posted December 21, 2007 Share Posted December 21, 2007 hi guys, i'm new in php and i would like to ask some question.See, let's say i got an html like this: <html><head><script>function dropOption(){ var file = new Array("1","2","3"); for(var i = 0; i<file.length; i++) { newopt = document.createElement("option"); newopt.text = file[i]; newopt.value = file[i]; try { document.getElementById("dropdown").add(newopt, null); } catch(ex) { document.getElementById("dropdown").add(newopt); //IE } }}</script></head><body><form action="sample.php" method="post"> Category: <select name="select" id="dropdown"> </select> <script type="text/javascript">dropOption();</script> <input type="submit" name="submit_button" value="Preview"/></form></body></html> Basically above is describe about drop down list.Below is php code with using RAP. <?php$select=$_POST['select'];//include RAPdefine("RDFAPI_INCLUDE_DIR", "D:/Web/WebServer/Apache2/htdocs/rap-v095/rdfapi-php/api/");include(RDFAPI_INCLUDE_DIR. "RdfAPI.php");//filename of an RDF document selected from the drop-down listif($select=="1"){$file="sample1.rdf" }elseif($select=="2"){$file="sample2.rdf" }elseif($select=="3"){$file="sample3.rdf" }//Create a newModel$model=ModelFactory::getDefaultModel();//load and parse rdf document$model->load($file);$model->writeAsHtmlTable();?> When the preview button is click, the .rdf file will load depends on which value select from the drop down list and preview the content. But my problem is.. let's say i have 20-30 value in dropdown list(which store in array) then my php code will have 20-30 if else statement. Is that any other ways to do it ? i got think using loop or i have to create new function?.. but i'm not so sure how as i'm newbie on this.Any help will be appreciated Link to comment Share on other sites More sharing options...
justsomeguy Posted December 21, 2007 Share Posted December 21, 2007 If all of the filenames match the dropdown values then you can just do this, you don't need a loop.$file="sample" . $select . ".rdf"; Link to comment Share on other sites More sharing options...
ohayo85 Posted December 21, 2007 Author Share Posted December 21, 2007 Thanks for reply.Sorry justsomeguy, i learn things a bit slow..$file="sample" . $select . ".rdf"; <--don't really understand. let's say my dropdown value is 1,2 and 3..then let's say my rdf file is 1.rdf, 2.rdf and 3.rdf...My thinking is..$file="??" .$select.".rdf";what should i put on the ??.. is it $select?Thanks in advance. Link to comment Share on other sites More sharing options...
ohayo85 Posted December 21, 2007 Author Share Posted December 21, 2007 nvm.. i got it solved .. thanks justsomeguy.. u rocks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.