Jump to content

billy_111

Members
  • Posts

    96
  • Joined

  • Last visited

    Never

Everything posted by billy_111

  1. Thanks, Your code worked! I also tried another method which also worked: $test = array('key1'=>'test1', 'key2'=>'value2', 'key3'=>array('test','test1','test2')); function transform(&$value){ $value = str_replace('test', 'frog', $value); } array_walk_recursive($test, 'transform'); print_r($test);
  2. Thanks, I just tried with this code: $test = array('key1'=>'test1', 'key2'=>'value2', 'key3'=>array('test','test1','test2')); $new_test = array(); foreach($test as $key=>$value) { if (strpos($value, 'test') !== FALSE) { $new_test[$key] = str_replace($value, 'hello', 'test'); } else { $new_test[$key] = $value; } } print_r($new_test); And i get this error: Any ideas what this problem might be?
  3. Hi, If i had the following array: $test = array('key1'=>'test1', 'key2'=>'value2', 'key3'=>array('test','test1','test2')); Is there a way i could change all the values that have the word "test" to "hello"? So basically end up with the following array: $test = array('key1'=>'hello1', 'key2'=>'value2', 'key3'=>array('hello','hello1','hello2')); Is this possible? Thanks
  4. haha you were right it was an sql error. I have now got the following sql: $sql = "INSERT INTO ConfPaper SET CPRid = ".$items[0].", Pid = ".$items[1].", CPtitle = '".mysql_real_escape_string($items[2])."', CPabstract = '".mysql_real_escape_string($items[3])."', CPspage = ".mysql_real_escape_string($items[4]).", CPepage = ".mysql_real_escape_string($items[5]).", CPfile = '".mysql_real_escape_string($items[6])."', CPlastedited = now(), CPUid = ".$_SESSION['Uid'].""; And it works! Ok now that this works perfectly, i need to add to it, i have a method already where i do this but i'm not quite sure how i will add it to the csv method. If you take a look at my csv file again: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/ConfPaper.csv You will notice i have Author at the end of each column, what i need to do it add these into another table. Now the way i currently do this is like so: public function insertAuthor($authArray, $PCorder=0) { $query = sprintf('SELECT Pid, Pname FROM People WHERE Pname IN(\'%s\') ORDER BY Pid ASC', implode('\',\'', $authArray)); $result = mysql_query($query); $maxquery = "SELECT MAX(CPid) as max FROM ConfPaper WHERE CPRid = ".$_GET['CPRid']; $maxresult = mysql_query($maxquery); $max = mysql_fetch_array($maxresult); $CPid = $max['max']; if($result && mysql_num_rows($result) > 0) { $sqlValues = array(); while(list($PId, $PName) = mysql_fetch_row($result)) { if(in_array($PName, $authArray)) { $sqlValues[] = sprintf("(%d, 1, ".$CPid.", %d, now(), 0)", $PId , $PCorder++ ); // Author already exists within the Pname table // remove user from $authArray $key = array_search($PName, $authArray); unset($authArray[$key]); } } $sql = "INSERT INTO PeopleCon(Person_id, PCHid, Pid, PCorder, PCdateadded, PCdeleted) VALUES \n"; $sql .= implode(",\n", $sqlValues); $result = mysql_query($sql); } // If there are Authors left within the $authArray // Add them to the Pname table if(count($authArray) > 0) { People::insertPersons($authArray); // call insertPersons method for remaining authors $this->insertAuthor($authArray, $PCorder); // insert the remaining auhtors into PeopleCon } } Insert persons is this: public function insertPersons($PName) { $query = "INSERT INTO People (Pname) VALUES ('" . implode("'), ('", $PName) . "')"; $result = mysql_query($query); } These methods together insert an array of authors into a table from a series of input textboxes, something a little like this: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php If you click on "add author" you can add however many textboxes and this method inserts all of them.. So now i need to combine this with my CSV file upload to do the same.. Is this possible?
  5. Hi, I am trying to insert the contents of a csv file into a table, this is my code: public function InsertCSVFileToDB(){ $has_title_row = true; $not_done = array(); if(is_uploaded_file($_FILES['csvfile']['tmp_name'])){ $filename = basename($_FILES['csvfile']['name']); if(substr($filename, -3) == 'csv'){ $tmpfile = $_FILES['csvfile']['tmp_name']; if (($fh = fopen($tmpfile, "r")) !== FALSE) { $i = 0; while (($items = fgetcsv($fh, 10000, ",")) !== FALSE) { if($has_title_row === true && $i == 0){ // skip the first row if there is a tile row in CSV file $i++; continue; } $sql = "INSERT INTO ConfPaper SET CPRid = ".$items[0].", Pid = ".$items[1].", CPtitle = '".mysql_real_escape_string($items[2])."', CPabstract = '".mysql_real_escape_string($items[3])."', CPspage = ".mysql_real_escape_string($items[4]).", CPepage = ".mysql_real_escape_string($items[5]).", CPlastesited = now()"; if(!mysql_query($sql)){ $not_done[] = $items; } $i++; } } // if there are any not done records found: if(!empty($not_done)){ echo "<strong>There are some records could not be inserted</strong><br />"; print_r($not_done); } } else{ die('Invalid file format uploaded. Please upload CSV.'); } } else{ die('Please upload a CSV file.'); } } This is the csv file: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/ConfPaper.csv But i keep getting this: Any ideas what the problem might be? Hope someone can help.. Thanks
  6. Hi again, One final final problem.. If you take a look at this link: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php And type in the box, if you type something that doesn't exist such as "John Barnes", the blue dropdown doesn't fade out, i have to either choose from the dropdown OR delete all the text.. Can i get around this? Thanks
  7. Ok it works beautifully now Let's hope i don't find any problems with it Again i can't thank you enough! Regards Billy
  8. Sorry my table had only one record inside, try with "Jo..".. I have noticed another problem, when you have more than one suggestion, (which you will when you type in "Jo..") I can't select the second and third option, only the first one. Maybe this is something i have done something to mess is up Also can you see the drop down issue when typing into the 1st box and it appears under the 6th? http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php
  9. Woohoo! Yep that worked. Just to be picky, there is one final thing, because i have position:relative on the div wrapping the suggestive text, it is making it appear below the "Current" textbox, this is fine when a user is adding one author, then the second and third etc.. But.. Let's say someone comes along and clicks on "Add author" 6 times because they need to add 6 authors and start typing in the first one. What will happen in the blue suggestive text will end up appearing under the 6th textbox when typing in the 1st one Can this be prevented in any way? Thanks again..
  10. Hey, I'm trying to do the upload method, see this code: public function updateAuthor($authArray, $PCorder=0) { $query = sprintf('SELECT Pid, Pname FROM People WHERE Pname IN(\'%s\') ORDER BY Pid ASC', implode('\',\'', $authArray)); $result = mysql_query($query); $deletequery = "DELETE t1, t2 FROM People AS t1 LEFT JOIN PeopleCon AS t2 ON t1.Pid = t2.Person_id WHERE t1.Pname IN('".implode('\',\'', $authArray)."')"; $delete = mysql_query($deletequery); if($result && mysql_num_rows($result) > 0) { $sqlValues = array(); while(list($PId, $PName) = mysql_fetch_row($result)) { if(in_array($PName, $authArray)) { $sqlValues[] = sprintf("(%d, 1, ".$_GET['ID'].", %d, now(), 0)", $PId , $PCorder++ ); // Author already exists within the Pname table // remove user from $authArray $key = array_search($PName, $authArray); unset($authArray[$key]); } } $sql = "INSERT INTO PeopleCon(Person_id, PCHid, Pid, PCorder, PCdateadded, PCdeleted) VALUES \n"; $sql .= implode(",\n", $sqlValues); $result = mysql_query($sql); } // If there are Authors left within the $authArray // Add them to the Pname table if(count($authArray) > 0) { People::insertPersons($authArray); // call insertPersons method for remaining authors $this->insertAuthor($authArray, $PCorder); // insert the remaining auhtors into PeopleCon } } They way i'm doing it is to delete the existing Authors and then re-insert.. Is this the correct way to do it? It does sort of work, but it doesn't do the re-insert, can you assist? My front end i call the method like this: $p = new Conferences(); $authors = array_filter(array_map('mysql_real_escape_string', $_POST['author'])); $p->updateAuthor($authors); Any ideas what i'm doing wrong? Thanks
  11. Hi, I'm trying to use the following delete query: DELETE FROM People LEFT JOIN PeopleCon ON People.Pid = PeopleCon.Person_id WHERE People.Pname = 'Peter Kay','Jake Welsh' Reason for doing it like this is i want to delete from 2 different tables which can be joined by an ID, table structure is below: I even tried doing it like this after a quick google search: DELETE t1, t2 FROM People AS t1 LEFT JOIN PeopleCon AS t2 ON t1.Pid = t2.Person_id WHERE t1.Pname = 'Peter Kay','Jake Welsh'; But had no luck. Any ideas? Thanks
  12. Thanks, I was actually going to post back about something else. Basically when there is no text in the textbox the dropdown suggestions should fade out.. So i looked at this function: if(elm.length == 0) { $('#AdminSuggestions' + num).fadeOut(); } Which i thought should fade the dropdown suggestion out when there is no text. But it does not seem to work. so i tried adding this: alert(elm.length); And i got "undefined".. Any ideas what the problem is?
  13. Woops! Silly me.. That works now, there are some css fixes as the drop down appears way over to the left, so i will get on with these Thanks for all your help, really appreciate it. Regards Billy
  14. Ok thats perfect, take a look http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php I can't thank you enough! Ok i'm not sure if this is a css issue, but when you get to the page, add about 8 textboxes and then start typing in the 8th box, try with name "Peter.." You will see that the drop down appears under the first text box, BUT fills the 8th textbox Is this done in the JavaScript? The reason why i'm asking is the CSS is has already been made to sit underneath the textbox.. so i assumed when more are added it would simply just dropdown under each one separately? Thanks again for your help..
  15. Ok again thanks for your response, i appreciate your help immensely That nearly worked, however what is happening now is that the predictive text is still only showing for one textbox, and also, you cannot select an option from the dropdown, so it's not clickable thus does not fill the textbox. I understand what you are suggesting, having input with different ID's so that the suggestions list is specific to each text box.. In regards to the fill method: function fill(elm, num) { setTimeout("$('#AdminSuggestions' + num).fadeOut();", 600); } I get a grey line under 'elm' and 'num', saying "unused".. Could it be this?
  16. This is my JavaScript at the top: <script type="text/javascript"> function suggest(inputString, inputFor){ if(inputString.length == 0) { $('#Adminsuggestions').fadeOut(); } else { $('#' + inputFor.id).addClass('load'); $.post("../view/includes/autosuggest.php", {queryString: ""+inputString+"", queryFor: inputFor.value}, function(data){ if(data.length >0) { $('#AdminSuggestions').fadeIn(); $('#AdminSuggestionsList').html(data); $('#' + inputFor.id).removeClass('load'); } }); } } function fill(thisValue) { $('#' + inputFor.id).val(thisValue); setTimeout("$('#AdminSuggestions').fadeOut();", 600); } </script> And then this is my textbox: <div id="AdminSuggest"> <label for="Author">Author:</label> <input type="text" name="author[]" id="authors" value="" onkeyup="suggest(this, 'admin');" onblur="fill();" style="margin-left:-1px"/> <div class="right" style="margin: 0 360px 0 0"><a href="#" id="add-line" onclick="addTextBox()">Add author</a></div> <div class="AdminSuggestionsBox" id="AdminSuggestions" style="display: none;"> <img src="../view/images/arrow.png" style="position: relative; top: 0px; left: 0px;" alt="upArrow" /> <div class="AdminSuggestionList" id="AdminSuggestionsList"> </div> </div> </div> Just thought i'd show you so you can see what i might be doing wrong?
  17. Hi, Thanks, i tried that but had no luck! :-\ Sorry i tried taking you to a page before which required login access. If you visit this page: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php you can see a textbox, with the ability to add more textboxes by the "add author" link. If you view the doctype you will see i have tried making some changes, but the predictive suggestions does not work.. Any ideas what i have missed out? Thanks
  18. Thanks, It's actually quite simple to call the method on different pages.. I have got it working thanks to your assistance.. However i have one problem. On this page: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/admin/testing.php I have made this so you can see what i am trying to do.. If you start typing, you will see the predictive text working perfectly on the first textbox. However now click on "add author" and start typing in the second box, if you select an option from the suggestions it fills the first textbox always. Is there way i can have the suggestions specific to each textbox? Regards Billy Thanks again
  19. Ok, the method's logic will run so that it checks to see if an author from table exists, if so add the results to a table called PeopleCon, else insert in to Poeple. From looking at my code, do you see any problems? How can i do this update statement..
  20. Thanks! I was actually trying to get the following code to work: public function LoadXml($origin, $destination){ $xml = simplexml_load_file("http://maps.google.com/maps/api/directions/xml?origin=".$origin."&destination=".$destination."&sensor=false"); foreach ($xml->xpath('//distance') as $distance): $lastvalue = $distance->value; endforeach; $total = $lastvalue * 0.00062137119; $total = number_format($total, 2); return $total; } I call the method from the front end like this; $review = Review::searchAllReviewsByTitlePoscodeAndAddress(); while($row = mysql_fetch_array($review)){ $pcode = PostcodeSearch::LoadXML($_GET['search'], $row['postcode']); } But it gives me an error saying it can't recognize "$lastvalue".. Any ideas? Thanks
  21. Hey Thanks! I have got this code: class PostcodeSearch{ public function LoadXml($origin, $destination){ $xml = simplexml_load_file("http://maps.google.com/maps/api/directions/xml?origin=".$origin."&destination=".$destination."&sensor=false"); foreach ($xml->xpath('//distance') as $distance): $lastvalue = $distance->value; endforeach; $total = $lastvalue * 0.00062137119; $total = number_format($total, 2); return $total; } } Then in my front end i have this: <? $review = Review::searchAllReviewsByTitlePoscodeAndAddress(); while($row = mysql_fetch_array($review)){ $pcode = PostcodeSearch::LoadXml($_GET['search'], $row['postcode']); ?> <div style="margin:0 0 10px 0; font-weight: bold">Distance: <span style="color:#990000"><?=$pcode?> miles</span></div> <? } ?> Now i am trying to get this working on this page: http://www.babiesinthecity.co.uk/search/?searchbutton=&search=M25 Notice i have already put in a search of "M25".. So basically for each review i loop through and check its postcode against the given input which in this case is "M25". The first result is "Heaton Park" which has a postcode of "M25 2SW".. If we put this into the xml link like so: http://maps.google.com/maps/api/directions/xml?origin=M25&destination=M25%202SW&sensor=false It gives no results.. Hence why i am getting the error on the display page: Yet if we look in Google: http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=M25+to+M25+2SW&sll=53.800651,-4.064941&sspn=11.488016,39.506836&ie=UTF8&t=h&z=15 It works fine. Any ideas why i am having this problem. This is all i need to do, just show the distance.. Don't understand why it won't work? Thanks
  22. Hi, I am trying to work with this xml page: http://maps.google.com/maps/api/directions/xml?origin=m20%202nu&destination=m5%205hf&sensor=false public function LoadXml(){ $xml = simplexml_load_file("http://maps.google.com/maps/api/directions/xml?origin=m20%202nu&destination=m5%205hf&sensor=false"); foreach ($xml->xpath('//distance') as $distance): echo $distance->value->getName() . ": " . $distance->value . "<br />"; endforeach; echo "<BR>"; foreach($xml->xpath('//leg') as $address): echo "The start address is: ".$address-> start_address.$address. "<br />"; echo "The end address is: ".$address->end_address.$address; endforeach; } what this code does is echo out the following: Now i don't need ALL the values, i only need the total value which is 10464. So is there a way to display the last child, or the final value? So all i want to show is value: 10464.. How can i access the final instance of the value? Thanks again
  23. Hi, I don't know how how difficult this is but i need to create a postcode search on the following site: http://www.babiesinthecity.co.uk/sea...ton=&search=M1 What you can see here is a set of "Reviews" which are being pulled out of a database. Each review has a postcode. Now what i need to show on this page is the distance the inputted postcode which is "M1" is to each review. I know i need an API, and i looked into http://code.google.com/apis/maps/documentation/directions/#XML The site is coded in PHP, but i don't quite know how or where to begin? Can anyone point me in the right direction? Thanks
  24. Ok thanks, I have only got around to doing this now, this is what i have: autosuggest.php $db = new mysqli('localhost', '****' ,'****', '****'); if(!$db) { echo 'Could not connect to the database.'; } else { if($_POST['queryFor'] == "author"){ $queryString = $db->real_escape_string($_POST['queryString']); if(strlen($queryString) >0) { $query = $db->query("SELECT CPtitle FROM ConfPaper WHERE CPtitle LIKE '%$queryString%' LIMIT 10"); if($query) { echo '<ul>'; while ($result = $query ->fetch_object()) { echo '<li onClick="fill(\''.addslashes($result->CPtitle).'\');">'.$result->CPtitle.'</li>'; } echo '</ul>'; } else { echo '<ul><li>Sorry no results found.</li></ul>'; } } else { // do nothing } } else { echo 'There should be no direct access to this script!'; } } And then i have this in my JavaScript: <script type="text/javascript"> function suggest(inputString, inputFor){ if(inputString.length == 0) { $('#suggestions').fadeOut(); } else { $('#documents').addClass('load'); $.post("includes/autosuggest.php", {queryString: ""+inputString+"", queryFor: inputFor}, function(data){ if(data.length >0) { $('#suggestions').fadeIn(); $('#suggestionsList').html(data); $('#documents').removeClass('load'); } }); } } function fill(thisValue) { $('#documents').val(thisValue); setTimeout("$('#suggestions').fadeOut();", 600); } </script> But i keep getting this: There should be no direct access to this script! So it does not recognize: if($_POST['queryFor'] == "author"){... Any ideas why it doesn't work, where is author set? This is my input text box: <input type="text" size="25" value="" id="documents" onkeyup="suggest(this.value, 'default');" onblur="fill();" class="searchtext" name="documents"/>
  25. Hi, I have the following code which basically checks an array of input textboxes and inserts them into a database table: public function insertAuthor($authArray, $PCorder=0) { $query = sprintf('SELECT Pid, Pname FROM People WHERE Pname IN(\'%s\') ORDER BY Pid ASC', implode('\',\'', $authArray)); $result = mysql_query($query); $maxquery = "SELECT MAX(CPid) as max FROM ConfPaper WHERE CPRid = ".$_GET['CPRid']; $maxresult = mysql_query($maxquery); $max = mysql_fetch_array($maxresult); $CPid = $max['max']; if($result && mysql_num_rows($result) > 0) { $sqlValues = array(); while(list($PId, $PName) = mysql_fetch_row($result)) { if(in_array($PName, $authArray)) { $sqlValues[] = sprintf("(%d, 1, ".$CPid.", %d, now(), 0)", $PId , $PCorder++ ); // Author already exists within the Pname table // remove user from $authArray $key = array_search($PName, $authArray); unset($authArray[$key]); } } $sql = "INSERT INTO PeopleCon(Person_id, PCHid, Pid, PCorder, PCdateadded, PCdeleted) VALUES \n"; $sql .= implode(",\n", $sqlValues); $result = mysql_query($sql); } // If there are Authors left within the $authArray // Add them to the Pname table if(count($authArray) > 0) { People::insertPersons($authArray); // call insertPersons method for remaining authors $this->insertAuthor($authArray, $PCorder); // insert the remaining auhtors into PeopleCon } } insertPersons method is as such: public function insertPersons($PName) { $query = "INSERT INTO People (Pname) VALUES ('" . implode("'), ('", $PName) . "')"; $result = mysql_query($query); } The logic works by firstly checking to see if an Author exists, if so they are inserted into PeopleCon, if not they are inserted into People AND PeopleCon. This all works perfectly.. But now what i need to do is build an update method where users can edit the authors also. The logic would be more or less the same, but i wouldn't neeed an insertpersons method, i would need to change it, and also the script would edit the existing authors, and if anymore are added apply the same method as above. Can anyone help me out as to how i should go about tackling this? Thanks Kind regards Billy
×
×
  • 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.