html - How to get the values of div using its id after retrieving the values from database using php -


i trying values of div elements using simple html dom parser. working fine hard coded values. here hard coded stuff.

<table> <tr><td class='none'><div class='drag' id='d1'>1</div></td></tr> <tr><td class='none'><div class='drag' id='d2'>2</div></td></tr> <tr><td class='none'><div class='drag' id='d3'>3</div></td></tr> 

apart these constant values need other id values displayed based on selection drop-down menu.

<form method="post" name="order" action="<?php echo $_server['php_self']; ?>"> <select id='test' name='test'> <option value="">please select</option> <option value='test1'>test1</option> <option value='test2'>test2</option> </select> </form> 

after selection click continue button redirects them same page , here script displays id's database.

<?php $i=4; if ($_server['request_method']=="post") {  $query = mysql_query("select * test_demo test_requested='$_post[test]'"); while($result=mysql_fetch_array($query)) { echo "<tr><td class='none'><div class='drag' id='d$i'>". $result['oid'] ."</div></td></tr>"; $i++; } } echo "</table>" ?> 

now want order id's 1,2,3 , remaining id's retrieved database. in order these values using values button on click goes retrieve.php file.

in retrieve.php file using simple html dom parser values. here code.

<?php include_once('simple_html_dom.php'); //test.php contains hard coded html , php code  $html = file_get_html('test.php'); $temp = '1';                     //usig div name retrieving values             foreach($html->find('div#d5') $e)         $result[]= $e->innertext;         print_r($result);   ?> 

in place of d5 if mention d1 or d2 or d3. able values 1,2,3 respectively. unable order id values retrieved database. div ids these elements starts d4 , on. going wrong?

there several issues.

first, php scripts aren't run if access them ordinary files. need change url go through server:

$html = file_get_html('http://localhost/path/to/test.php'); 

second, need provide value of test parameter in url, should be:

$html = file_get_html('http://localhost/path/to/test.php?test=test1'); 

third, in test.php need access parameter using $_get, not $_post, when it's accessed way:

if ($_server['request_method'] == "get") {     $test = mysql_real_escape_string($_get['test']);     $query = mysql_query("select * test_demo test_requested='$test'");     ... } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -