Jump to content

billy_111

Members
  • Posts

    96
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    UK - Manchester

billy_111's Achievements

Member

Member (2/5)

0

Reputation

  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?
×
×
  • 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.