Jump to content

marksie1988

Members
  • Posts

    225
  • Joined

  • Last visited

Everything posted by marksie1988

  1. Is no one able to assist with this? Im really struggling to get it working. Or if you can point me in the direction of a similar method to create a dropdown menu that will mark the parent as active when using a sub menu that would be great.
  2. Hi Guys, I have the below code that I am trying to make work correctly, basically it creates a menu structure and then should only make the parent active if the page you are on belongs to that parent. at the moment the structure is wrong as it is adding too many <ul> entries for each menu. this is what it currently does: <ul id="nav"> <li class="active"><a href="admin.php">System Settings</a> <ul id="nav"> <li><a href="reports.php">Reports</a></il> </ul> <ul id="nav"> <li><a href="memblst.php?opt=createuser">Create User</a></il> </ul> </li> </ul> This is what it should be: <ul id="nav"> <li class="active"><a href="admin.php">System Settings</a> <ul> <li><a href="reports.php">Reports</a></il> <li><a href="memblst.php?opt=createuser">Create User</a></il> </ul> </li> </ul> $MENU["SYSTEMS"] = array ( 'parent'=>true, 'enabled'=>true, 'text'=>'System Settings', 'link'=> 'admin.php', 'sub_modules' => array('REPORTS','CREATE_USER') ); $MENU["REPORTS"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Reports', 'link'=> 'reports.php', 'sub_modules' => array() ); $MENU["CREATE_USER"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Create User', 'link'=> 'memblst.php?opt=createuser', 'sub_modules' => array() ); $MENU["MEMBER_LST"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Member List', 'link'=> 'memberlst.php', 'sub_modules' => array() ); $MENU["SYSTEM_LOGS"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'System Logs', 'link'=> 'syslog.php', 'sub_modules' => array() ); function show_menu(&$MENU,$subIndex=false){ $menu_string = ''; $menu_string .= '<ul id="nav">'; if(!$subIndex){ foreach($MENU as $item) { if( $item['enabled']&&$item['parent'] ) { $_subString=""; if(!empty($item['sub_modules'])){ foreach($item['sub_modules'] as $sub){ $_subString .= show_menu($MENU,$sub); } } $menu_string .= '<li class="active"><a href="'.$item['link'].'">'.$item['text'].'</a>'.$_subString.'</li>'; } } }else{ if(@$MENU[$subIndex]['enabled']&&!@$MENU[$subIndex]['parent']) { $_subString=""; if(!empty($MENU[$subIndex]['sub_modules'])){ foreach($MENU[$subIndex]['sub_modules'] as $sub){ $_subString .= show_menu($MENU,$sub); } } $menu_string .= '<li><a href="'.$MENU[$subIndex]['link'].'">'.$MENU[$subIndex]['text'].'</a></il>'.$_subString; } } return $menu_string.'</ul>'; } echo show_menu($MENU);
  3. Hi Guys, I have been working on a recursive select box that will allow sub-categories and keep getting the error: <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>test.php</b> on line <b>22</b><br / i have a table as follows: CREATE TABLE IF NOT EXISTS `ost_help_topic` ( `topic_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `isactive` tinyint(1) unsigned NOT NULL DEFAULT '1', `noautoresp` tinyint(3) unsigned NOT NULL DEFAULT '0', `priority_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `dept_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `CatParent` bigint(11) unsigned DEFAULT NULL, `topic` varchar(32) NOT NULL DEFAULT '', `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`topic_id`), UNIQUE KEY `topic` (`topic`), KEY `priority_id` (`priority_id`), KEY `dept_id` (`dept_id`) ) <?php $db_host = "localhost"; $db_un = "user"; $db_pass = "pass"; $Item_DB = "data"; $table = "ost_help_topic"; $link = mysql_connect($db_host, $db_un, $db_pass); $tab = " "; // this is 8 spaces, which works as a pseudo-tab character inside the <option>s $tablvl = 1; function print_kids($pos) { // $pos is the current position inside the hierarchy (curr item's ID) global $link; global $tab; global $tablvl; $pos = ($pos?$pos:null); $query = "SELECT * from $table WHERE isactive=1 AND CatParent".($pos == null ? " IS NULL" : "=".$pos); // NULL parent == top level item. For 0-parents, replace " IS NULL" with "=0" $res = mysql_db_query($Item_DB, $query, $link); if (!$res) print(mysql_error()); while($row = mysql_fetch_array($res)) { $has_kids = mysql_fetch_array(mysql_db_query($Item_DB, "SELECT * from $table where isactive=1 AND CatParent=$row[0]", $link)) != null; print("<option value=\"$row[0]\">"); for ($i=0; $i<$tablvl; $i++) print($tab); print("$row[6]</option>\n"); if ($has_kids) { $tablvl++; print_kids($row[0]); // <span class="posthilit">recursive</span> call $tablvl--; } } } $numrows = 1; $res = mysql_db_query($Item_DB, "SELECT * FROM $table", $link); while (mysql_fetch_array($res)) $numrows++; // Yes, I'm sure there's a more efficient way to do this <img src="./images/smilies/icon_razz.gif" alt="" title="Razz" /> print("<select name=\"hierarchy\" size=\"$numrows\">\n"); print("<option value=\"null\" selected=\"selected\">Root of all items</option>\n"); print_kids(0); print("</select>"); mysql_close($link); ?>
  4. Hi Guys, i have got a script that gets directions from point a to point b etc, i need to also output the distance of the journey which will populate a div further down the page below is my code but i dont know why i cant get the distance to show in the div. function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("svmap_canvas"),{mapTypes:[G_NORMAL_MAP]}); gdir = new GDirections(map, document.getElementById("svmap_directions")); var mapControl = new GMapTypeControl(); map.addControl(mapControl);map.addControl(new GSmallMapControl());map.enableDoubleClickZoom();map.enableScrollWheelZoom();var geocoder = new GClientGeocoder(); var myIcon = new GIcon(); myIcon.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png"; myIcon.iconAnchor = new GPoint((markerImage1.width/2),markerImage1.height); markerOptions = { icon:myIcon, draggable: false, "title":"Drax Solutions LLP" }; var point1 = new GLatLng(53.7726417, -1.7056978); map.setCenter(point1, 10); var marker1 = new GMarker(point1, markerOptions); map.addOverlay(marker1); var distance = gdir.getDistance(); document.getElementById("roundmiles").innerHTML = distance; } }
  5. Hi Guys, i have the below script which works out the driving distance between 2 points i am not great with JS and the google API and cant figure this out! how do I create a poly line on the route that the 2 points has taken? i cant figure out how to get it to display on a map that i put in my html var geocoder, location1, location2, gDir; function initialize() { geocoder = new GClientGeocoder(); gDir = new GDirections(); GEvent.addListener(gDir, "load", function() { var drivingDistanceMiles = (gDir.getDistance().meters / 1609.344).toFixed(1); var drivingDistanceKilometers = gDir.getDistance().meters / 1000; document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + ' (' + location1.lat + ':' + location1.lon + ')<br /><strong>Address 2: </strong>' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles (or ' + drivingDistanceKilometers + ' kilometers)'; document.getElementById('miles').value = drivingDistanceMiles * 2; }); } function showLocation() { geocoder.getLocations(document.forms[0].address1.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; geocoder.getLocations(document.forms[0].address2.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; gDir.load('from: ' + location1.address + ' to: ' + location2.address); } }); } }); } the html i currently have is: <h2>Calculate Distance</h2> <center> <form action="#" onsubmit="showLocation(); return false;"> <table class="grid_table"> <tr class="grid_row_even"> <td class="grid_cell">From Address: </td><td class="grid_cell"><input type="text" name="address1" class="address_input" size="40" /></td> </tr> <tr class="grid_row_even"> <td class="grid_cell">To Address:</td><td class="grid_cell"> <input type="text" name="address2" class="address_input" size="40" /></td> </tr> </table> <input type="submit" name="find" value="Search" /> </p> </form> <p id="results"></p> </center>
  6. Ok that makes sense, but how would i ensure that each file was the latest version? Would you sugest that i have a DB with each version of each file and if this all matches then they are on the latest version (this would save changing the version in files that havent been changed) then i could have a line in the table for the main version and if the main version changes they must do a full update :S
  7. Hi Guys, Sorry if this is the wrong forum but i wasnt sure the best one. i am trying to see how others control the version of apps they have written and updating. i want to set the version of my app e.g. 1.0 and then have a section where if i release 1.5 it will show up that a new version is available for upgrade. the only thing im not too sure about is when someone goes to upgrade if not all of the updated files are uploaded correctly i want it to say version missmatch. could someone give me examples of how i could achieve this?
  8. Hiu Guys, having a bit ov an issue with this havent had to do anything like this before but here goes below you will see my php code which calls all of the tickets from hd_ticket and then explodes the email address to get the domain.com once it has this i need to select the domain.com from the hd_customers table and update the hd_ticket table company column with the information from the hd_customers table. for some reason when it runs the nested while loop it doesnt loop through all of the results it only displays one on the echo i have also put my table structure to help you out. hd_customers id email company 1 domain.com mycompany hd_tickets ticket_id ticketID dept_id priority_id topic_id staff_id email name subject helptopic phone phone_ext ip_address status source isoverdue isanswered duedate reopened closed lastmessage lastresponse created updated company $sql= 'SELECT * FROM hd_ticket '; $result = mysql_query($sql)or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ $fromco = explode("@",$row[email]); $fromco = $fromco[1]; $sql= 'SELECT * FROM hd_customer WHERE email="'.$fromco.'"' ; $result = mysql_query($sql)or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ $company = $row[company] ; $sql= 'UPDATE hd_ticket ticket SET ticket.company='.$company.''; print $sql; //mysql_query($sql); } } //}
  9. i am fairly sure that the query is wrong: INSERT INTO products SELECT * FROM tempproduct WHERE manf_part_no NOT IN (SELECT manf_part_no FROM products) AND supp_id NOT IN (SELECT supp_id FROM products) i think that it needs to be something along the lines of: INSERT INTO products SELECT * FROM tempproduct WHERE manf_part_no NOT IN (SELECT manf_part_no FROM products) AND supp_id = (SELECT supp_id FROM products) unfortunatly im not sure how to do a command like this could someone help and i think that may fix the error i get with the script
  10. this is MSSQL not MYSQL it works differently and allows you to do it like this but php doesnt seem to like this?
  11. hi i have the script below which copies data from one table to another but will only insert new data update current data or delete old data from tempproducts to products then it will delete the tempproducts from the db however i keep getting this error: Warning: mssql_query() [function.mssql-query]: Query failed in E:\UpdateProducts.php on line 33 updateproducts.php <?php include('../../otherscripts/functions.php'); $log = new Logging(); // create DB connection $host = "localhost"; $user = "user"; $pass = "pass"; $mydb = "db"; $db = mssql_connect($host,$user,$pass); //Select Database mssql_select_db($mydb); // delete all old data $sql0 = "SELECT * FROM tempproduct"; $sql1 = "INSERT INTO products SELECT * FROM tempproduct WHERE manf_part_no NOT IN (SELECT manf_part_no FROM products) AND supp_id NOT IN (SELECT supp_id FROM products)"; $sql2 = "DELETE FROM products WHERE manf_part_no NOT IN (SELECT manf_part_no FROM tempproduct) AND supp_id NOT IN (SELECT supp_id FROM tempproduct)"; $sql3 = "UPDATE p1 SET p1.avail_qty = t1.avail_qty, p1.cost_price = t1.cost_price, p1.rrp = t1.rrp, p1.date_added = t1.date_added, p1.description = t1.description FROM Products p1 INNER JOIN tempproduct t1 ON (p1.manf_part_no = t1.manf_part_no AND p1.supp_id = t1.supp_id)"; $sql4 = "TRUNCATE TABLE tempproduct"; //If tempproduct is empty done Execute Commands if it is full then execute commands $query = mssql_query($sql0) or die($log->lwrite('Failed to select for count from db')); $rowcount = mssql_num_rows($query); if($rowcount == 0){ $log->lwrite('Teh tempproduct am emptyish'); } else{ mssql_query($sql1) or die($log->lwrite('Failed to insert to db'.$sql1)); mssql_query($sql2) or die($log->lwrite('Failed to Delete from db')); mssql_query($sql3) or die($log->lwrite('Failed to Update db')); mssql_query($sql4) or die ($log->lwrite('Failed to TRUNCATE db')); } ?> if i run $sql1 command in the sql manager it runs fine and no errors occur?
  12. ok i now have an issue with the fixed script that if the csv file has a column with e.g. Dell Computer Memory\ it will think that the \ is signifying a new column so it says there the field count is incorrect on the row with the \ is there i way i can str_replace this from the csv file? when i add it to the script where the current str_replace is it doesnt work.
  13. Hi, i have a table which will hold products in it but first the products are imported to tempproducts so that i can update the products where there is a change i created the following update command but i keep getting the following error: Msg 4104, Level 16, State 1, Line 4 The multi-part identifier "dbo.tempproduct.manf_part_no" could not be bound. Msg 4104, Level 16, State 1, Line 5 The multi-part identifier "dbo.tampproduct.supp_id" could not be bound. UPDATE dbo.products SET dbo.products.avail_qty = dbo.tempproduct.avail_qty FROM dbo.products WHERE dbo.products.manf_part_no = dbo.tempproduct.manf_part_no AND dbo.products.supp_id = dbo.tampproduct.supp_id i havent been using mssql for long as i mainly use mysql so am not too sure on some things like this. help appreciated Steve
  14. thats wicked works great thankyou so much help much appreciated
  15. the blank lines are only ever at the bottom of the CSV file so i dont suppose this would make it easier? one idea would be to open the csv file remove the blank lines save it and then start again with the script to import the csv file to the DB
  16. Anyone else have any Ideas how to do this?? Cheers
  17. unfortunately this gives the same issue: Erroneus CSV file: incorrect field count on row 14388 row 14388 is a blank row
  18. ok i think that it still sees the blank rows as i get this error: Erroneus CSV file: incorrect field count on row 14388 row 14388 is a blank row
  19. once i had changed the foreach i got the error: Parse error: syntax error, unexpected '{' in E:\CSV\CSV_GALTEC\ImportScripts\ccd.php on line 47 line 47: if(!preg_match("~\S~", $v){
  20. Parse error: syntax error, unexpected T_AS in E:\CSV\CSV_GALTEC\ImportScripts\ccd.php on line 45 line 47 if(!preg_match("~\S~", $v){ also changed foeach($fields as $v) to: foreach($fields as $v)
  21. Hi Thanks, unfortunately i get this error: Warning: preg_match() expects parameter 2 to be string, array given in E:\CSV\CSV_GALTEC\ImportScripts\ccd.php on line 43 line 43 is: if(count($data)==count($fields) && $i!=1 && preg_match('~[\S]~', $data)){
  22. Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the end i need to somehow tell it to skip the rows that have nothing on them: <?php // define table name and csv file location and name $supp_id = "15"; $pricecode = "6"; $csvupload = "../ccd/Catalogue_ZZMILGAT.csv"; // create DB connection $host = "localhost"; $user = "user"; $pass = "pass"; $mydb = "db"; $table = "table"; $db = mssql_connect($host,$user,$pass); mssql_select_db($mydb); // delete all old data $sql2 = "DELETE FROM ".$table." WHERE supp_id = ".$supp_id.""; mssql_query($sql2) or die("Failed to insert to db "); // Define DB mapping (Fill in rest of the mapping in order of appearance in CSV) $fields = array( "manufacturer", "ignore", "manf_part_no", "supp_part_no", "description", "rrp", "cost_price", "avail_qty"); // Open the CSV file $handle = fopen($csvupload, "r") or die("Unable to open $csvupload for reading"); // Get each row's values to an array $i = 1; // define tab delimited or comma while (($data = fgetcsv($handle, 512, ",")) !== FALSE) { // First row's headers and not included, otherwise row field count must match wanted field count if(count($data)==count($fields) && $i!=1){ $rows[] = $data; } elseif(count($data)!=count($fields)) { die("Erroneus CSV file: incorrect field count on row $i"); } $i++; } // Close file handle fclose($handle); // Create SQL if(count($rows)==0) die("No rows found in user file"); // Remove last comma foreach($rows as $i => $row){ $sql = "INSERT INTO ".$table." ("; foreach($fields as $field) if($field!="ignore") $sql .= "$field,"; $sql = substr($sql,0,-1).",supp_id, date_added, PriceCode) VALUES "; $sql .= "("; foreach($row as $j => $value){ if($fields[$j]!="ignore"){ if(empty($value)) $value = "0"; // Quote strings, try to remove existing quotes elseif(!is_numeric($value)) $value = str_replace("'","",$value); $value = str_replace("\"","",$value); $sql .= "'$value',"; } } $sql = substr($sql,0,-1).",'".$supp_id."', getdate(),'".$pricecode."')"; // Remove last comma //echo "SQL became: $sql"; mssql_query($sql) or die("Failed to insert to db "); } ?>
  23. Hi, i have now managed to get this code problem is when i have my select statement for the query i get an echo of resource id #1resource id #2resource id #3 etc how can i fix this? <?php define ('GALTEC' , 1); define ('COMPANY_NAME', 2); define ('OTHER_COMP' , 3); // create DB connection $host = "localhost"; $user = "user"; $pass = "pass"; $mydb = "database"; $table = "products"; $db = mssql_connect($host,$user,$pass); mssql_select_db($mydb); function process_csv( $csvupload, $from_company, $callback ) { $handle = fopen($csvupload, 'r') or die("Unable to open $csvupload for reading"); $head = array(); // You said that each company always sends you files with the same columns. // Describe the differenct columns here, for each company separately. If // the first row of the CSV file already contains the field names, you can // also simply read them, as I did with GALTEC. switch( $from_company ) { case GALTEC: $head = fgetcsv( $handle, 512, ',' ); // Don't forget to catch any errors. break; case COMPANY_NAME: // I don't know what the content of each column is, so I'm making the names up. $head[] = 'supp_part_no'; // e.g., REMANG-BT350 $head[] = 'manf_part_no'; // e.g., ADG-BT350 $head[] = 'description'; // e.g., Qfax BT350/370 ALTERNATE TTR $head[] = 'avail_qty'; // e.g., .000 $head[] = 'cost_price'; // e.g., 6.27 $head[] = 'SUPPLIER'; // e.g., AD $head[] = 'COMMENT'; // everything after the last comma break; case OTHER_COMP: // This company supplies us with a CSV file that contains a header, but we // use different field names, so we read the first lnie, then override the // field names. $flush = fgetcsv( $handle, 512, ',' ); // Don't forget to catch any errors. $head[] = 'PRODUCT'; // e.g., REMANG-BT350 $head[] = 'SUPPLIER'; // e.g., AD $head[] = 'TYPE'; // e.g., ADG-BT350 $head[] = 'SIZE'; // e.g., .000 $head[] = 'AKA'; // e.g., Qfax BT350/370 ALTERNATE TTR $head[] = 'PRICE'; // e.g., 6.27 $head[] = 'COMMENT'; // everything after the last comma break; } // At tihs point, $head should always contain the same column names, // regardless of the company that sent the CSV file. Only the order // may differ from company to company $i = 1; while ( false !== ( $data = fgetcsv( $handle, 512, ',' ) ) ) { if( count( $data ) == count( $head ) ) { $callback( array_combine( $head, $data ) ); } else { die("Erroneus CSV file: incorrect field count on row $i"); } } } function process_record($row) { $select = "SELECT * FROM FindMeStock.dbo.products WHERE manf_part_no = '".$row['manf_part_no']."' AND supp_id = '1'"; $qry = mssql_query($select) or die("Failed to select from DB"); // At this point, $row is an array with the following structure: // $row = Array ( [PRODUCT] => REMANG-BT350 [TYPE] => ADG-BT350 [AKA] => Qfax BT350/370 ALTERNATE TTR [size] => .000 [PRICE] => 6.27 [sUPPLIER] => AD [COMMENT] => ) // Note that you can now access each item using standard indexes: //echo $row['PRODUCT'], ' '; } process_csv( 'pricelist.csv', COMPANY_NAME, 'process_record'); ?>
×
×
  • 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.