Jump to content

DCM

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Everything posted by DCM

  1. I think i have solved my first query by casting the contents to TEXT as below so i can now do partial queries: SELECT * FROM network_table WHERE network::TEXT LIKE '%192.%'; I would still however really appreciate a practical example of how some of the more advanced cidr functions can be used to for example: 1> Determine if a network exists. 2> If a new network allocation falls within the range of an already existing network. If the network 192.168.1.0/24 exists then i would like to be able to detect that allocating 192.168.1.16/28 would cause a conflict.
  2. Hi i have a table which contains IP networks stored as a cidr data type in postgreSQL. I have read the offical support page on both inet and cidr but I cannot find a simple practical example where this data type is queried in SQL statement, at least not to achieve the below? if for example the table was as follows: Network_Name | Network_Address ---------------------------------------------- Network A | 192.168.1.0/24 Network B | 192.168.2.0/24 Network C | 192.168.3.0/24 Network D | 10.1.1.0/24 Network E | 10.1.2.0/24 Network F | 10.1.3.0/24 How can i construct an SQL query querying data stored in the Network_Address that matches/contains the users search criteria of say '192.168.': I would like this to return all the 192.168.x.x networks. This seems to work with the inet type as it lets you use the LIKE command but cidr will not allow this. If i type in the full Network address is works, but i need to be able to do partial searches. I would also like to be able to do more advanced things such as checking if a network already exists or overlaps/conflicts with current assigned networks. From what i have read i think i may need to do something called casting with the functions available to the cidr data type but i'm not really sure how to go about it. Thanks for reading, any pointers are appreciated
  3. Thanks thats fixed it I added 'AddType application/x-httpd-php .php' to the following section: <IfModule mime_module> AddType application/x-httpd-php .php </IfModule> I do use short tags occassionly yes but i should probably go away and change them to the full version. Thank you again very much for you prompt assistance.
  4. Hi I am tryng to get PHP/Apache working on a windows 2003 server (standard edition 32 bit). I currently have this setup working on my XP machine and i have used the same installers/locations/config files. However Apache is not parsing the PHP files, i simply get the raw text outputted. The specifics of my install are: - Windows 2003 server 32bit standard edition - Apache - httpd-2.2.16-win32-x86-no_ssl.msi - PHP - php-5.2.14-win32-installer.msi - Apache install dir: c:\apache - PHP install dir: c:\php I have also attached my php.ini file and httpd.conf file as this must be where the issue lies but i cannot see it I have renamed the atatched files .txt so i can post them on here Any help advice is greatly appreciated, I dont understand my this wont work as its pretty much a direct port of a working config on my XP machine. [attachment deleted by admin]
  5. Thanks I'll give it a try.. I was also looking at array_splice which may also work without me having to sort the array. Idealy i do not want to disturb the order in which data is displayed in the array as it (in my real app) will have been pr-ordered by the user selecting from a sort by radio button selection. making progress though so thanks.
  6. typo in presious reply, the original array is defined as : $_SESSION['myarray'][0][0] = "aaa"; $_SESSION['myarray'][0][1] = "111"; $_SESSION['myarray'][1][0] = "bbb"; $_SESSION['myarray'][1][1] = "222"; $_SESSION['myarray'][2][0] = "ccc"; $_SESSION['myarray'][2][1] = "333"; $_SESSION['myarray'][3][0] = "ddd"; $_SESSION['myarray'][3][1] = "444";
  7. Sure the above is simply and example but if example the array at present is as above such that the values assigned are $_SESSION['myarray'][0][0] = "aaa"; $_SESSION['myarray'][0][1] = "111"; $_SESSION['myarray'][1][0] = "bbb"; $_SESSION['myarray'][1][1] = "222"; $_SESSION['myarray'][2][0] = "ccc"; $_SESSION['myarray'][2][1] = "333"; $_SESSION['myarray'][2][0] = "ddd"; $_SESSION['myarray'][2][1] = "444"; A quick for loop to output the results given that $numrecs currently equals 4 for ($x=0; $x<$numrecs; $x++) { echo $_SESSION['myarray'][$x][0] ."<br>"; echo $_SESSION['myarray'][$x][1] ."<br>"; } would give as output: aaa 111 bbb 222 ccc 333 ddd 444 If say record $_SESSION['myarray'][1] has been deleted in the back end data base and $numrecs reduced by one, then on refresh of the webpage i would the contents of the array to display as: aaa 111 ccc 333 ddd 444 However at present i can't seem to get this to work, to delete the data in the array I do unset ($_SESSION['myarray'][1][0]); unset ($_SESSION['myarray'][1][1]); However on re-running the for loop i then get the below as output: aaa 111 ccc 333 When it should be: aaa 111 ccc 333 ddd 444
  8. Hi I have a multi-dimension session array as per the below: $_SESSION['myarray'][][] If for example there are several elements stored in the array: $_SESSION['myarray'][0][0] = "aaa"; $_SESSION['myarray'][0][1] = "111"; $_SESSION['myarray'][1][0] = "bbb"; $_SESSION['myarray'][1][1] = "222"; $_SESSION['myarray'][2][0] = "ccc"; $_SESSION['myarray'][2][1] = "333"; $_SESSION['myarray'][2][0] = "ddd"; $_SESSION['myarray'][2][1] = "444"; How can i remove one of the above and shunt the other elements up? I have tried using the unset command but this seems to essentailly nullify the desired values where as what i would like to do is remove them completly from the array and then shorten the total number of records stored in the array. Thanks for taking the time to read this.
  9. Thanks for the reply. At the moment i cannot even seem to get the contents of my $_POST['chbox_delete_host_record'] I have tried various ways, such as testing if it isset, doing a foreach loop but all the time no results are returned. Is there a flaw in the way i am trying to detect which checkboxes have been ticked? The unique value I am assigning is the hostname which is stored in a $?S_SESSION['hosts'][][] array where S_SESSION['hosts'][$x][0] is the hostname for each device. Its this i use when setting the value attribute of the checkbox: <input type='checkbox' name='chbox_delete_host_record[]' value='".$_SESSION['hosts'][$x][0]."'>
  10. I still cant seem to get this working, could anyone please point out what i'm doing wrong. Given i have a session array along the lines of: $_SESSION['hosts'][$x][0] = "HostA" // stores hostname $_SESSION['hosts'][$x][1] = "IP address" //stores IP address $_SESSION['hosts'][$x][2] = "VLAN" // stores VLAN // in reality the data is loaded into the above array from a postgresql DB. // When cylcing through to output the users search results I tag a check box onto the end // of each row of data returned in a for loop as follows for ($x=0; $x < $result_count; $x++) { //other code.... echo "<td><input type='checkbox' name='chbox_delete_host_record[]' value='".$_SESSION['hosts'][$x][0]."'></td>"; } //Upon the user clicking a delete_multiple_hosts button i then try to detect which checkboxes have been aciviated with: if (isset ($_POST['delete_multiple_hosts'])) { for ($x=0; $x < $result_count; $x++) { if (isset ($_POST['chbox_delete_host_record[$x]'])) { echo "checkbox has been activiated for host".$_SESSION['hosts'][$x][0]; //obviously other code would go here i'm just trying to detect which boxes have been checked at present } } }
  11. Hi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading.
  12. Is it possible to set the vertical viewing start posiiton of a page? Instead of the page starting from the top each time it is loaded i want to be able under certain circumstances to present the user with a with a viewing position that is lower down on the page (for example when displaying search results). Thanks for reading.
  13. Thanks for the reply, i think i follow the logical (although I am using postgresql not mysql, my fault i should have said). The part i dont really get is where the final WHERE clause is created, could you please elaborate on the follwoing line: $WHERE = (count($whereParts)>0) ? 'WHERE '.implode(' AND ', $whereParts) : ''; I am assuming that the implode command outputs the contents of the $whereParts array but i dont get the syntax of how that line cycles through and creates the where part?
  14. I am trying to work out how to correctly format an SQL query string from user data taken from multiple HTML text boxes/dropdowns. As an example assuming i have a searach page on which the user can enter search criteria into the following fields: name - text box site_location - drop down box (default set to 'search all') job_title - drop down box (default set to 'search all') manager - drop down box (default set to 'search all') email - textbox Its easy when all fields have user data set or one has user data set but when the user has entered data into only a couple of the fields I have problems constructing the SQL query, namely when it comes to adding the 'AND' keyword into the SQL query. No matter how i try to set out the logic in the PHP code i seem to end up with at least one combination of the search critea leading to back to back AND statements. I construct the SQL query by appending a string variable $query with the relevant search criteria, for example: $query = "select * from employees where "; if ($_POST['name'] != null) { $query=$query."name='".$_POST['name']."' "; } if ($_POST['site_location'] != 'all') { $query=$query."AND site_location='".$_POST['site_loaction']."' "; } //etc This does not work out though when fields are empty, I have tried adding additional if statements to check ahead to see if fields further down in the query are required and if so append an 'and' but I cannot seem to get the logic correct. Is this something anyone else has come accross, if so is there a better solution than the route i am going down? Thanks for reading.
  15. Thanks the way i did it in the end was to use a session variable that got set by the function. I tried the way you suggested but maybee i was missing something obvious.
  16. Hi i have a function strored in a seperate file (included in my main php page for use), my question is a simple one but i cannot seem to find the answer on the web to this: I call the function as follows passing the variable $name <?php myfunction($name) ?> The function does somehting simple such as: <?php function myfunction ($name) { if ($name = 'bob') { return true; } else return false; } ?> How do i then obtain the true or false value of the function from back with my main php page?
  17. Thats great thanks a lot.
  18. Thanks that works although i am having a real problem interpreting the syntax of that regular expression, need to do some backgroung reading i think on PH and regex.
  19. Hi, what is they best way to validate user input of strings? A couple of examples would be : 1> If i wanted to check for the existance on the coma ',' character in a string and replace it with a dash '-' character? 2> To check wether a user has entered a valid ip address in the form of x.x.x.x where x can range from 0-255? I think i may need ereg/preg to do this but i have no idea about how to layout the syntax. Thanks for looking.
  20. Guys thanks a lots that works for me now, i know it must be frustrating whe us newbies ask such basic stuff! I was getting hung up on how you define arrays in the likes of java, the php syntax just seems a bit weird but I understand it now. One more question if i may, am i correct in assuming this syntax is only applicable for multi-dimensional arrays in $_SESSION arrays and that a standard multi-dimension array in php could still be defined as: $myarray[0][0 ]; Thanks again for the advice it really has helped me out
  21. The way I understood a php array to work as in java for example is as below: $hosts[x][y]; // Where x tracks how many hosts are stored in the array and y stores any number of // details about record x, i.e. $hosts[0][0] // = The hostname for the first item in the array $hosts[0][1] // = The ip addressfor the first item in the array $hosts[0][2] // = The operating system for the first item in the array $hosts[1][0] // = The hostname for the second item in the array $hosts[1][1] // = The ip addressfor the second item in the array $hosts[1][2] // = The operating system for the second item in the array What i am trying to do is hold this data as a session array so upon a page reload the data in the array is not lost, as below: $_SESSION['hosts[0][0]'] // = The hostname for the first item in the array $_SESSION['hosts[0][1]'] // = The ip addressfor the first item in the array $_SESSION['hosts[0][2]'] // = The operating system for the first item in the array $_SESSION['hosts[1][0]'] // = The hostname for the second item in the array $_SESSION['hosts[1][1]'] // = The ip addressfor the second item in the array $_SESSION['hosts[1][2]'] // = The operating system for the second item in the array When referencing this array I have no problem using intergers to reference and output the data, i.e. $_SESSION['hosts[0][0]'] = "hosta"; echo $_SESSION['hosts[0][0]'] ; // outputs hosta However: $_SESSION['hosts[0][0]'] = "hosta"; $x=0; echo $_SESSION['hosts[$x][0]'] ; // returns no output So the above becomes an issue when trying to output results from the array using for loops.
  22. I can now access data from within my session array as below echo $_SESSION['hosts[5][1]']; However i do not seem to be able to access the results when refernceing the array with a variable, for example: $x=5; echo $_SESSION['hosts[$x][1]']; Is this a limitation or is there a way around it? Thanks again for any advice
  23. Thanks so would i reference the data as: $_SESSION['hosts'][$x][0]; or $_SESSION['hosts[$x][0]'];
×
×
  • 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.