Jump to content

xxclear

Members
  • Posts

    34
  • Joined

  • Last visited

Everything posted by xxclear

  1. Thanks for your reply, that alone returns: var_dump($result); //this returns: col1, $value1, col2, $value2, col3, $value3 Notice "=" isn't inserted between each exploded result. What do i need to do to get that function to work between each result? FYI i get: PHP Parse error: syntax error, unexpected T_FUNCTION, expecting ')' In the original code.
  2. Can some help me make this code backward compatible? This code works with php 5.3 and above. I need it to work with 5.2.17. $columns = 'col1, col2, col3'; $values = '$value1, $value2, $value3'; $result = implode( ', ', array_map( function ($c, $v) { return $c . ' = ' . $v; }, explode(',', $columns), explode(',', $values) ) ); var_dump($result); //this returns: col1 = $value1, col2 = $value2, col3 = $value3 Cheers.
  3. Typical, i got it to work just as i was getting a print out for here. It seems that if i put in a date with a garbage keyword it gets the row with the date but if i don't put in a keyword it ignores the date... i thought the OR operator was supposed to overcome that? "The OR operator displays a record if either the first condition or the second condition is true." as taken from W3C
  4. Use onclick or onfocus functions in javascript http://www.webdeveloper.com/forum/showthread.php?191521-Show-Hide-div-based-on-Radio-button
  5. Thanks for replying. So this is what i did: $query = " SELECT id, auditor, auditee, datum, department, func, proc, audit_type, copy_to, comments FROM audit_data WHERE `auditor` LIKE '%$search_field%' OR `auditee` LIKE '%$search_field%' OR `department` LIKE '%$search_field%' OR `func` LIKE '%$search_field%' OR `proc` LIKE '%$search_field%' OR `audit_type` LIKE '%$search_field%' OR `id` = '$radio_id' OR `datum` = '$datum' " $result = mysqli_query($link, $query ) OR die(mysqli_error($link)); got a parse error on $result = mysqli_query($link, $query ) This is the real code i need it to work on btw, if it helps. What have a i done wrong?
  6. ok so i have set the query to a variable and used : print_r($result_debug); I get echoed back: "mysqli_result Object ( )" Where do i go from here, because your right: $result = mysqli_query($link, " SELECT id, col1, col2, datum, col4, col5, col6, col7, col8, col9FROM table WHERE `datum` = '$datum' " ) OR die(mysqli_error($link)); Doesn't work, and its killing me.
  7. Would echoing $result have the same affect?
  8. How do I search a column for a date which is stored as a var? Is this the best way? $result = mysqli_query($link, " SELECT id, col1, col2, datum, col4, col5, col6, col7, col8, col9 FROM table WHERE `datum` = '$datum' " ) OR die(mysqli_error($link)); Thanks in advance.
  9. Don't shy away chap & chapettes, any advice will be appreciated.
  10. I have tried it on my server and i'm getting the same error, the browser wasn't rendering it as expected, if you right click of the "Link" and inspect element you will see what i mean. Try setting a new variable above the echo and then try escaping the quotes with backslashes like this: $inf = $info['file']; echo "<a href=\"C:\php\website\files\'.$info['file'].'\">Link</a>"; If it still doesn't work it should at least give you a "Link". We can go from there.
  11. Breaking it down might help. echo "<a href=C:\php\website\files\'.$info['file'].'>"; echo "Link</a>"; What you are doing is letting the browser render its own quotes in the right place after the php has finished. (after the "=" and before the ">").
  12. It is possible but can i ask why? It would only work once as you can only have one database connected to website at any one time. are you sure you don't want to just create a new table? <?php $con=mysqli_connect("example.com","peter","abc123"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Create database $sql="CREATE DATABASE my_db"; if (mysqli_query($con,$sql)) { echo "Database my_db created successfully"; } else { echo "Error creating database: " . mysqli_error(); } ?> as taken from W3C schools You would need to create an input form and use POST if you want it to be user controlled,
  13. You have single quotes inside single quotes there. Echo "<a href=C:\php\website\files\'.$info['file'].'>Link</a>"; Does that work ^^
  14. Highlight the code and press the button that looks like "<>"
  15. Can you put code quotes around the code so its highlighted, people maybe more inclined to help that all. like this
  16. Ok, so i am trying to compare a date stored as a variable against a row in mysql, this is where i am so far: I need to be able to search the table for: 1) a search keyword 2) a combination of a date, for example (just 2013) or (march-2012) or (7th of june) or (5th of september 2012) or (just the 16th) etc... $result = mysqli_query($link, " SELECT id, auditor, auditee, datum, department, func, proc, audit_type, copy_to, comments FROM audit_data WHERE ( `auditor` LIKE '%$search_field%' OR `auditee` LIKE '%$search_field%' OR `department` LIKE '%$search_field%' OR `func` LIKE '%$search_field%' OR `proc` LIKE '%$search_field%' OR `audit_type` LIKE '%$search_field%') OR (`id` = '$radio_id') OR (datum = '$datum') " ) OR die(mysqli_error($link)); Its only a small table otherwise I would be indexing. The variable and row are both stored in native format (YYYY-MM-DD) (If i put in a keyword into my $search_field it displays all the rows with a match, that works a treat). The above example shows an exact match between the row and var which as it happen doesnt work. I have a calender setup on the input form and search form that will put in any date like this 2013-04-08 or 2013-00-08 etc. Logically this is what i want (unfortunately doesn't work): if day($datum) = "00" {day($datum) = ""} else { day($datum) = day($_REQUEST['date1'] } if month($datum) = "00" {month($datum) = ""} else { month($datum) = month($_REQUEST['date1'] } if year($datum) = "0000" {year($datum) = ""} else { year($datum) = year($_REQUEST['date1'] } // select select * from audit_data where `datum` = if(isset(day($datum))){day($datum)} OR if(isset(month($datum))){month($datum)} OR if(isset(year($datum))){year($datum)} OR OR [search keyword code here] date1 being the calender output... If the above seem odd, or simply wrong, forgive me, im just trying to get the point across as clear as i can. Can anybody give me a head start on how to do this, any advice, links, examples, structure will be greatly appreciated!
  17. @lluvatar hahaha you and me both mate. i am trying to combine/merge 2 arrays in a loop. Take a look at this as an example. first loop outputs this: Array ( [10] => Yes [11] => No [12] => Yes [13] => No [14] => Yes [15] => No [16] => Yes [17] => No [18] => Yes [19] => No [20] => Yes [21] => No [22] => Yes [23] => No [24] => Yes [25] => No [26] => Yes [27] => No [28] => Yes [29] => No [30] => Yes [31] => No [32] => Yes [33] => No ) second loop outputs this: Array ( [10] => comment [11] => comment [12] => comment [13] => comment [14] => comment [15] => comment [16] => comment [17] => comment [18] => comment [19] => comment [20] => comment [21] => comment [22] => comment [23] => comment [24] => comment [25] => comment [26] => comment [27] => comment [28] => comment [29] => comment [30] => comment [31] => comment [32] => comment [33] => comment ) third loop outputs this: Array ( [10] => Yes comment [11] => No comment [12] => Yes comment [13] => No comment [14] => Yes comment [15] => No comment [16] => Yes comment [17] => No comment [18] => Yes comment [19] => No comment [20] => Yes comment [21] => No comment [22] => Yes comment [23] => No comment [24] => Yes [25] => No [26] => Yes [27] => No [28] => Yes [29] => No [30] => Yes [31] => No [32] => Yes [33] => No [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => ) third loop should output like this: Array ( [10] => Yes comment [11] => No comment [12] => Yes comment [13] => No comment [14] => Yes comment [15] => No comment [16] => Yes comment [17] => No comment [18] => Yes comment [19] => No comment [20] => Yes comment [21] => No comment [22] => Yes comment [23] => No comment [24] => Yes comment [25] => No comment [26] => Yes comment [27] => No comment [28] => Yes comment [29] => No comment [30] => Yes comment [31] => No comment [32] => Yes comment [33] => No comment ) I have narrowed it down to this loop. // loop 3 combines the answers and comments for($x = 0; $x < count($comment); $x++){ $question[$x] = $question[$x] . ' ' . $comment[$x]; } $result = $question; // saves the answers and comments as a string ($result) print_r ($result); Sorry for my ignorance, i am learning php and only been at it a few weeks. Appreciate the reply!
  18. Turns out my for loops are only counting to 14 regardless of where i start. Still can't figure it out.
  19. does it say what it is expecting instead of T_STRING?
  20. I have extensively searched the web for this but haven't found anything that can help! At the moment I have three loops: // loop 1 finds the answers if(isset($_POST['qanswer'])){ ($question = $_POST['qanswer']); for($i=0; $i < count($question); $i++) { echo "POSTED ANSWERS" . $question[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Answers POSTED!</p>'; } // loop 2 finds the comments if(isset($_POST['canswer'])){ ($comment = $_POST['canswer']); for($i=0; $i < count($comment); $i++) { echo "POSTED COMMENTS" . $comment[$i] . "<br/>"; } } else { echo '<p style="color: Red">No Comments POSTED!</p>'; } // loop 3 combines the answers and comments for($x = 0; $x < count($comment); $x++){ if(isset($question[$x])){ $question[$x] = $question[$x] . ' ' . $comment[$x]; } } $result = $question; // saves the answers and comments as a string ($result) Each comment[$i] is the same key and $question[$i]. Inserting into the table i have: $query = "INSERT INTO audit_data (Q4101, Q4102, Q4103, Q4104, etc...) VALUES '$result[0]','$result[1]','$result[2]','$result[3]','$result[4]', etc...)"; mysqli_query($link, $query) or die(mysqli_error($link)." Q=".$query); 1) is this the best way to go about this? 2) It is nearly working, i can get the $question and $comment into the first columns for instance: $result[0] to result[10] but if i try to insert further on in the table say $result[40] to $result[50] i only get the $question values and no $comment values. I have looked at array_map and preg_match on the manual but not sure how or which one to use. I don't want the table normalized and i am aware of injection problems.
  21. Thanks for you patience, I understand now. its all clicked into place. Took long enough! i have to specify the columns if there is going to be null values otherwise how does mysql know where i want the data? hehe. im sure i will find a better way of doing this, maybe a while loop, but i cant run before i can walk. cheers again!
  22. This is the code that works, without this working the system wont allow me to generate a header and therefore wont allow me to submit an audit. if ($_SERVER['REQUEST_METHOD'] == 'POST') { $query = "INSERT INTO audit_plan VALUES ('','$_POST[auditor]','$_POST[auditee]','$_POST[datum]','$_POST[department]','$_POST[function]','$_POST[proc]','$_POST[audit_type]','$_POST[copy_to]','$_POST[comments]')"; mysqli_query($link, $query); } notice the quotes are outside the variable, don't know why this works but it does.
  23. I don't understand, i have got this to work before in my planning section, the only difference is its a different table and more information from a different form how can it be so complicated? Also, its in an intranet and controlled by radio buttons so no need for security at this point.
×
×
  • 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.