Jump to content

jacsdev

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by jacsdev

  1. hi man, how are you? try this, I think this script can solve it.. by the way, check attach file, it have a table named data.sql and example.php <?php // By @jacsdev $cnx = mysql_connect("localhost","root","",true); mysql_select_db("test",$cnx); // i have a table called data // data have field1, field2, field3 (without primary key) // we want insert values, but we need to have ascendents numbers in field1 // sql script (data.sql) have in field1 next values: 1, 3, 4, 5 ( however not number 2) // we need than next inserted row be 2 (in field1) $cn = mysql_query("select field1, field2, field3 from data order by field1 asc",$cnx); $numRows = mysql_num_rows($cn); $i = 1; while($rs = mysql_fetch_array($cn)) { if( $rs['field1'] != ( $numRows - ($numRows - $i) ) ) { break; } $i++; } // now, we can do insert query, and field1 will have correct number $field2 = 4; $field3 = 5; mysql_query("insert into data (field1, field2, field3) values ($i,$field2, $field2 )",$cnx); // let see result echo "F1 - F2 - F3<br>"; $cn = mysql_query("select field1, field2, field3 from data order by field1 asc"); while ($rs = mysql_fetch_array($cn) ) { // you must see number 2 in field1 position echo $rs['field1']." - ".$rs['field2']." - ".$rs['field3']."<br>"; } ?> [attachment deleted by admin]
  2. what's up man!!! how are you?, maybe you must verify the mysql query string, check if it produces any data result. you can try the following: copy and paste your query in sql option of phpmyadmin, and run it... then verify if your query works now, when you choose a server and the page is loaded again, you must define the query that you'll use for extract new results of the other table.. also you must write the instruction that transforms query in a array type.. ex: //below line where it say, we need write other instruction .. $cn_server = mysql_query("SELECT * FROM CES WHERE Name ='".$server."'"); //here while ($rs_server = mysql_fetch_array($cn_server)) { echo $rs_server['here i write name of field']; } //hey, a little fix, inside validateForm function, instead myServer, write myServers by te way, i saw than you write ' echo "SOME TEXT" ' inside select tag, well, in that place you can't see output data, just it possible in the option tag value: <option>here i am visible</option> @jacsdev
  3. Hi, what's up??? i think right now in a simple solution. there are many more solutions, i would like with ajax, but first the first <?php // @jacsdev // define your data connection $host = ''; $user = ''; $pwd = ''; $db = mysql_connect($host, $user, $pwd) or die("Sorry, it's not possible"); mysql_select_db($dbName); if(isset($_GET['server']) && !empty($_GET['server'])) { $server = $_GET['server']; // now, as you see, we have in $server the value selected in dropdown list // so, we can do our query now: // this query is an example, you can modify $cn_server = mysql_query("select * from other_table_with_data where server_name='".$server."'"); //.. } ?> <form action="" onsubmit="return validateForm();"> Choose a Server: <select name="myServers" id="myServers" onchange="selectMyServer(this.value);"> <option value="-">-</option> <?php $cn = mysql_query("select server_name, server_ip, server_type from server_list_table"); while($rs = mysql_fetch_array($cn)) { ?> <option value="<?php echo $rs['server_name']; ?>"><?php echo $rs['server_name']; ?></option> <?php } ?> </select> <br /> <br /> <input type="submit" value="Send Data" /> </form> <script language="javascript" type="text/javascript"> function selectMyServer(server) { if(server != '-') { // i get current page var myCurrentPage = location.href; // now, i setting my current page. we must add selected server in new url location.href = myCurrentPage +'?server=' + server; // redirecting to curret page } } function validateForm() { if(document.getElementById('myServer').value !='-') { alert('please, choose a server'); return false; } } </script> when you choose a server in dropdown, the onChange event is launched. this event invoke to selectMyServer function, passing selected server as argument... so, the function redirect to same page with the name of selected server and then you can do a query with this value.. i hope help you friend @jacsdev
  4. Hi, Kevin, whats up? i saw your post in forum... well, i think you can solve that sutation with php xpath, in this way: Lets say, we have xml file named feed.xml, like this: feed.xml: <?xml version="1.0" encoding="UTF-8"?> <data> <item> <product>apple</product> <manufacturer>macbook</manufacturer> </item> <item> <product>mobile phone</product> <manufacturer>nokia</manufacturer> </item> <item> <product>vaio</product> <manufacturer>sony</manufacturer> </item> <item> <product>Play Station</product> <manufacturer>sony</manufacturer> </item> </data> So, we want extract all items that belong to sony manufacturer.. here the solution with php xpath: <?php // By @jacsdev $productList = array(); $xml = simplexml_load_file("feed.xml"); $result = $xml->xpath('/data/item[manufacturer="sony"]'); // this is query type called xpath, it mean: it seek every item where manufacture="sony" $i = 0; foreach($result as $item) { $productList[$i] = $item->product; // this give product name // note that item have: <product> and <manufacturer> tag, // so in this case we could to get respective values with $item->product and $item->manufacturer // ouput echo $productList[$i]; echo "<br>"; $i++; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.