PHP - Combine 2 Elements From 2 Different Arrays To Same Record
I have 2 arrays, this is the first:
while($r = mysql_fetch_array($result)){ $arr[] = array(1 => $r[1], 2 => $r[2], 3 => $r[3], 4 => $r[4], 5 => $r[5], 6 => $r[6], 7 => $r[7], 8 => $r[8], 9 => $r[9]); }And this is the second: foreach ($arrGROUPED as $key => $row3) { if($row3[1].$row3[2] != $printedFirst){ $arrHIGHEST_RESULT[] = array(1 => $row3[1], 2 => $row3[2], 3 => $row3[3], 4 => $row3[4], 5 => $row3[5], 6 => $row3[6], 7 => $row3[7], 8 => $row3[8]); } $printedFirst = $row3[1].$row3[2]; }I'm trying to print a results table using the following: echo" <tr ><td align=\"center\" $style>$pos</td> <td align=\"center\" $style><a href=\"playerDates.php?FName={$row3['1']}&LName={$row3['2']}\">" . $row3[1] .' '. $row3[2] . "</a></td> <td align=\"center\" $style><a href=\"venueDates2.php?VenueName={$row3[3]}\">" . $row3[3] . "</a></td> <td align=\"center\" $style>" . $row3[6] . "</td> <td align=\"center\" $style>" . $row3[7] . "</td> <td align=\"center\" $style>" . $r[9] . "</td> <td align=\"center\" $style>" . $row3[8] . "</td> </tr>";And all of the data shows perfectly EXCEPT the second last line where I try to print $r[9]. I think this is because I need to associate $r[9] from the first array with the appropriate record in the second array. But I can't figure out how to do that! In plain English I want to print $r[9] where $r[1], $r[2], $r[3] from the first array are equal to $row3[1], $row3[2], $row3[3] from the second array. I've got no idea how to go about it, so any help would be great Similar TutorialsI've been working on this too long, without having it figured out. Starting to get a bit 'kooky' at this point! I'm one stage away from retarded frustration. I have two arrays, such as these: Array 1 ( => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) Array 2 ( => 8|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 ) I am trying to write a piece of code that will compare every value in array 2 to every value in array 1 and if the first 2 NUMERICAL values do not exist in Array 1, they are to be added to it. So, in the end, after comparison, Array 1 should look like this: Array 1 ( => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 => [7] => 8|1|0|5|0|0 [8] => 7|2|0|5|0|0) The values 7|3|0|5|0|0 and 7|4|0|5|0|0 from Array 2 have not been added to Array 1 because 7|3... and 7|4... already exist in Array 1. So far, I've got something like this: Code: [Select] $match = 0; foreach ($array1 as $data1) { foreach ($array2 as $data2) { if ($data1 == $data2) { $match = 1; break; } } if ($match != 1) { array_push($array1, $data2); } else {$match = 0;} } Where have I gone wrong? I have a brain twister in a script i'm working on. It have a multidimensional array that hold values to populate a google charts js script. To make it work as I plan I need to merge the data from similar arrays together. I'll give an example and hopefully it will make more sense. Also, this page is being loaded over ajax so, the faster/smaller the better. Example Array: Code: [Select] Array ( [0] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [1] => Array ( [item] => 1 [quant] => 2 [price] => 12.5 [day] => 18 [onl] => ) [2] => Array ( [item] => 1 [quant] => 5 [price] => 12.5 [day] => 17 [onl] => 1 ) [3] => Array ( [item] => 1 [quant] => 12 [price] => 12.5 [day] => 19 [onl] => 1 ) [4] => Array ( [item] => 1 [quant] => 4 [price] => 12.5 [day] => 21 [onl] => ) ) So since array 0 and 1 both have data from sales on the 18th for the same item I would want to merge them into a single array and leave all others in the parent array the same. I apologize in advance if this doesn't make sense, I've been working too many hours. X| If anyone knows of a good solution for this or perhaps a better approach, that would be great. Thank You, E I have two arrays, X and Y, which contain names. The arrays are of the same size. The arrays are related to each other such that for each pair X[n] , Y[n] X is friends with Y. For example: X[0,1,2] = [Link, Cloud, Cloud, Mario, Mario, Luigi] Y[0,1,2] = [Zelda, Barrett, Tifa, Luigi, Bowser, Mario] Link is friends with Zelda Cloud is friends with Barrett and Tifa Mario is friends with Luigi and Bowser Luigi is friends with Mario I want to loop through these arrays and, for each unique name, find all of that person's friends. I then want to print the results to a text file, like so: Link, Zelda Cloud, Barrett, Tifa Mario, Luigi Luigi, Mario I know how to do this theoretically, but I just need help with the PHP syntax. Thanks very much. I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
Hi guys, im currently querying my database and if ($row) im including a file. But i would like to make it so if ($row) or a session variable is active, to include the file. I have tried using || but ive only ever used that for regular variables and I cant get it working in the way i want. so at the moment i have Code: [Select] if ($row) ( require 'myfile'; and i would like to add || $_SESSION['email'] is active. im guessing i would use isset, but i just cannot get it working. Hello I have this query and it is working well: Code: [Select] $data = mysql_query(" SELECT `title`, `body`, 'condoms_en' as REF FROM `condoms_en` UNION SELECT `title`, `body`, 'discr_en' as REF FROM `discr_en` UNION SELECT `title`, `body`, 'diseases_en' as REF FROM `diseases_en` UNION SELECT `title`, `body`, 'express_en' as REF FROM `express_en` UNION SELECT `title`, `body`, 'gender_en' as REF FROM `gender_en` UNION SELECT `title`, `body`, 'get_informed_en' as REF FROM `get_informed_en` UNION SELECT `title`, `body`, 'get_tested_en' as REF FROM `get_tested_en` UNION SELECT `title`, `body`, 'newly_en' as REF FROM `newly_en` UNION SELECT `title`, `body`, 'news_hiv_en' as REF FROM `news_hiv_en` UNION SELECT `title`, `body`, 'nutrition_en' as REF FROM `nutrition_en` UNION SELECT `title`, `body`, 'phdp_en' as REF FROM `phdp_en` UNION SELECT `title`, `body`, 'press' as REF FROM `press` UNION SELECT `title`, `body`, 'r_o_en' as REF FROM `r_o_en` UNION SELECT `title`, `body`, 'stats_en' as REF FROM `stats_en` UNION SELECT `title`, `body`, 'stigma_en' as REF FROM `stigma_en` UNION SELECT `title`, `body`, 'think_news_en' as REF FROM `think_news_en` UNION SELECT `title`, `body`, 'think_reports' as REF FROM `think_reports` UNION SELECT `title`, `body`, 'treatment_en' as REF FROM `treatment_en` where`title` like '%$kw%' OR `body` like '%$kw%'") or die(mysql_error()); $rows = mysql_num_rows($data); I need to add to the same query this part: Code: [Select] SELECT `cont`, 'about_us_en' as REF FROM `about_us_en` UNION SELECT `que`,`ans`, 'faq_en' as REF FROM `faq_en` UNION SELECT `orga`, `lnk`, 'links_en' as REF FROM `links_en` UNION SELECT `title`, `desc`, 'publications' as REF FROM `publications` IF I add this part as is, I get an error saying that the select has different columns. Please Help and how do I modify the where if they are combined?! Thank you hello i`m trying something but cant seem to get it working it purpose is this ; open 2 files goodies.txt has : heavy big small goodies2.txt has : rock toy brick and i want it to pick from goodies.txt first word and combine it to all words in goodies2.txt something like this: heavy-rock heavy-toy heavy-brick and then big-rock big-toy big-brick read file <?php $file=file('goodies.txt'); $file1=file('goodies2.txt'); foreach($file as $files){ $split=explode("\n",$files); for($i=0;$i<count($file1);$i++) { $combine=$split[0].$file1[$i]; echo $combine; } } } i dont know if my logic is good in this case :| Gud Eve peeps! So i have 2 variable strings: Code: [Select] $variable1 = item, item, item; $variable2 = number, number, number; I need to make this 2 variables into 1 array being variable 1 as a key value and variable 2 as a variable.. and i tried combining them using: Code: [Select] $array = array_combine($variable1, $variable2); the problem is some item name are the same so it just overwrites the other so instead of giving me this: Array ([item] => number, [item] => number, [item =>number]) it gives me this: Array ([item =>number]) I really need them to be complete because i will loop each key and value to be inserted to a new row in my db.. thanks again for the help! Hi Everyone, I am trying to add on to this mobile detection script that I have been using (quite nicely I might add) from http://detectmobilebrowsers.com/ Code: [Select] <?php // check for mobile browser $useragent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) // redirect if mobile browser header('Location: http://www.example.com/mobile/'); ?> I would like to use/combine some sort of redirect link for users who are redirected to the mobile site to be ridirected back to the full site and vice versa. I wrote a quick $_GET example below, but would rather use $_SESSIONS if possible to make it more transparent/invisible. My question is how best to combine the code above with the code below and get it to work? Code: [Select] <a href="http://www.example.com/?mobile">View Mobile Site</a> <a href="http://www.example.com/?full">View Full Site</a> <?php if ($_GET['mobile']) { $variable = true; } if ($_GET['full']) { $variable = false; } ?> Any help, suggestions, or examples would be appreciated. Thanks in advance, kaiman I know this involves MySQL, but it's mostly PHP, so I figured it should go here, forgive me if I posted in the wrong section, though. Anyway! Let's get down to it. I'd like to combine these two scripts (below). I want the questionnaire script to be a signup requirement in the signup script, and I want it to log the questionnaire into my MySQL database as usual, then prompt the user with a successful sign up. I'm still really new to PHP and I'm just testing to see if this'll work. How would I go about doing this? Thanks a LOT guys. Questionnai <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Questionnaire'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>'; exit(); } // Show the navigation menu require_once('navmenu.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // If this user has never answered the questionnaire, insert empty responses into the database $query = "SELECT * FROM mismatch_response WHERE user_id = '" . $_SESSION['user_id'] . "'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // First grab the list of topic IDs from the topic table $query = "SELECT topic_id FROM mismatch_topic ORDER BY category_id, topic_id"; $data = mysqli_query($dbc, $query); $topicIDs = array(); while ($row = mysqli_fetch_array($data)) { array_push($topicIDs, $row['topic_id']); } // Insert empty response rows into the response table, one per topic foreach ($topicIDs as $topic_id) { $query = "INSERT INTO mismatch_response (user_id, topic_id) VALUES ('" . $_SESSION['user_id']. "', '$topic_id')"; mysqli_query($dbc, $query); } } // If the questionnaire form has been submitted, write the form responses to the database if (isset($_POST['submit'])) { // Write the questionnaire response rows to the response table foreach ($_POST as $response_id => $response) { $query = "UPDATE mismatch_response SET response = '$response' WHERE response_id = '$response_id'"; mysqli_query($dbc, $query); } echo '<p>Your responses have been saved.</p>'; } // Grab the response data from the database to generate the form $query = "SELECT mr.response_id, mr.topic_id, mr.response, " . "mt.name AS topic_name, mc.name AS category_name " . "FROM mismatch_response AS mr " . "INNER JOIN mismatch_topic AS mt USING (topic_id) " . "INNER JOIN mismatch_category AS mc USING (category_id) " . "WHERE mr.user_id = '". $_SESSION['user_id'] . "'"; $data = mysqli_query ($dbc, $query); $responses = array(); while ($row = mysqli_fetch_array($data)) { array_push($responses, $row); } mysqli_close($dbc); // Generate the questionnaire form by looping through the response array echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">'; echo '<p>How do you feel about each topic?</p>'; $category = $responses[0]['category_name']; echo '<fieldset><legend>' . $responses[0]['category_name'] . '</legend>'; foreach ($responses as $response) { // Only start a new fieldset if the category has changed if ($category != $response['category_name']) { $category = $response['category_name']; echo '</fieldset><fieldset><legend>' . $response['category_name'] . '</legend>'; } // Display the topic form field echo '<label ' . ($response['response'] == NULL ? 'class="error"' : '') . ' for="' . $response['response_id'] . '">' . $response['topic_name'] . ':</label>'; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="1" ' . ($response['response'] == 1 ? 'checked="checked"' : '') . ' />Love '; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="2" ' . ($response['response'] == 2 ? 'checked="checked"' : '') . ' />Hate<br />'; } echo '</fieldset>'; echo '<input type="submit" value="Save Questionnaire" name="submit" />'; echo '</form>'; // Insert the page footer require_once('footer.php'); ?> Signup: <?php // Insert the page header $page_title = 'Sign Up'; require_once('header.php'); require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { // Grab the profile data from the POST $username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1'])); $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2'])); if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) { // Make sure someone isn't already registered using this username $query = "SELECT * FROM mismatch_user WHERE username = '$username'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // The username is unique, so insert the data into the database $query = "INSERT INTO mismatch_user (username, password, join_date) VALUES ('$username', SHA('$password1'), NOW())"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>'; mysqli_close($dbc); exit(); } else { // An account already exists for this username, so display an error message echo '<p class="error">An account already exists for this username. Please use a different address.</p>'; $username = ""; } } else { echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>'; } } mysqli_close($dbc); ?> <p>Please enter your username and desired password to sign up to Mismatch.</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Registration Info</legend> <label for="username">Username:</label> <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br /> <label for="password1">Password:</label> <input type="password" id="password1" name="password1" /><br /> <label for="password2">Password (retype):</label> <input type="password" id="password2" name="password2" /><br /> </fieldset> <input type="submit" value="Sign Up" name="submit" /> </form> <?php // Insert the page footer require_once('footer.php'); ?> And here are the pastebins in case you prefer those: http://pastebin.com/pTXGSMT9 - Questionnaire http://pastebin.com/28jZhYyY - Signup Thanks! I have a small form which executes a php file, and the executable php file. is there anyway to have it just using the 1 php file? form code: Code: [Select] <form enctype="multipart/form-data" action="upload-exec.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> uploader.php Code: [Select] <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> i did try using: Code: [Select] if (isset($_POST['submit'])) { with no luck. Many thanks Hi I have an array which looks a little like this, the first number in each array is a quantity $cars = array ( array(1,"BMW",15,13), array(8,"BMW",15,13), array(3,"Saab",5,2), array(4,"BMW",11,7), array(5,"Land Rover",17,15), array(6,"Saab",5,2) ); what I want to do is combine any array which matches another, but ignoring the quanitity value (first one). Then creating the array again and adding up the quanitity values and re-inserting them at the start. Therefore the end result would look like $cars = array ( array(9,"BMW",15,13), array(9,"Saab",5,2), array(4,"BMW",11,7), array(5,"Land Rover",17,15), ); Has anyone got any ideas on how I might do this? Thanks Edited July 23, 2020 by John84$id[] = 12345; $id[] = 12345; $id[] = 12345; $id[] = 12345; $id[] = 12345; how would I combine these into a string "12345,12345,12345,12345,12345" I have 3 variables that im still cleaning up but they produce results at least. I have spent a couple days searching how to execute (exec or shell_exec) them in order. The best iv found, this is done like Code: [Select] $statementa = 'cd test"' then do this"' exec=($statementa) but what i am doing is a bit more complicated Code: [Select] $tempFolder = 'C:\\xampp\\htdocs\\remote\\'; $filename7Z = 'C:\\xampp\\7-zip\\7z.exe'; $sessionKey = '12345' $commandtest1= 'C:\\xampp\\7-zip\\7z.exe a ' .$tempFolder. 'c' .$sessionKey. '.7z C:\\xampp\\htdocs\\remote\\client\\ helpdesk.txt icon1.ico icon2.ico icon3.ico winvnc.exe'; //semi working, copies entire dir $commandtest2 = 'copy /b C:\\xampp\\htdocs\\remote\\support\\7zS.sfx+ C:\\xmapp\\htdocs\\remote\\client\\config.txt+'.$tempFolder.'c'.$sessionKey.'.7z c'.$sessionKey.'.exe'; //create executable in build directory \\\\not working\\\\\\ $commandtest3 = 'del /F /Q '.$tempFolder.'\\c'.$sessionKey.'.7z'; //remove *.7z from %tmp% directory \\\\\\\\\working\\\\\\\ //session_write_close(); exec($commandtest1); Where i cant seem to find any guidance is, if i wrap these in " then is looks fine in dreamweaver but produces nothing. I think it may be the variables but i cant be sure. I tried todo $exec($commandtest1 & $commandtest2) but that didn't help any then i tired ($commandtest1 | $commandtest2) still noting. It seems i can just have three exec so i have to comine into one however i have several breaks where it need todo the first then sencond then third. Please someone point me in the correct direction. I must have read http://php.net/manual/en/function.exec.php at least 6 times and either miss is each time or haven't been able to apply it to my code correctly Hi all I have written a bit of code that I need to change from 4 seperate SQL queries into 1 so I can paginate the results. My code is below: Code: [Select] <!-- Get Trader premium adverts --> <?php $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'premium' AND paid = 1 AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); $numtraderads = mysql_num_rows($gettraderads); while ($showtraderads = mysql_fetch_array($gettraderads)) { include('trader-ad-cell.php'); } ?> <!-- Get Trader standard adverts --> <?php $gettraderads = mysql_query("SELECT * FROM `trade-adverts` WHERE type = 'standard' AND categoryid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); $numtraderads = mysql_num_rows($gettraderads); while ($showtraderads = mysql_fetch_array($gettraderads)) { include('trader-ad-cell.php'); } ?> <!-- Get premium adverts --> <?php $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'premium' AND paid = 1 AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); while ($showads = mysql_fetch_array($getads)) { include('ad-cell.php'); } ?> <!-- Get standard adverts --> <?php $getads = mysql_query("SELECT * FROM `adverts` WHERE categoryid = 1 AND type = 'standard' AND live = 1 AND approved = 1 AND dateexpired >= '".$todaysdate."' ORDER BY id DESC "); while ($showads = mysql_fetch_array($getads)) { $standarduserid = $showads['userid']; $getstandarduserinfo = mysql_query(" SELECT * FROM `users` WHERE id = '".$standarduserid."'"); $showstandarduserinfo = mysql_fetch_array($getstandarduserinfo); include('standard-ad-cell.php'); } ?> Can anyone help me? Many thanks Pete i have an array with 5 numbers... Code: [Select] $numbers = array(1 => 4; 2 => 26; 3 => 15; 4 => 36 5 => 9); I need a method to combine them in sets of three.. For example: 4, 26, 15 4, 26, 36 4, 26, 9 and so on ... Have ten possible combinations. Any idea or advice of how i could do this...? I have this part of the code: for($number_words_loop = 0; $number_words_loop < $number_words; $number_words_loop++) { $value1 .= 'AND a.adtitle RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; $value2 .= 'AND a.addesc RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; } And I want to combine $value1 and $value2, so the code should look something like this: for($number_words_loop = 0; $number_words_loop < $number_words; $number_words_loop++) { $value .= 'AND a.adtitle RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\' OR AND a.addesc RLIKE \'[[:<:]]' . $words[$number_words_loop] . '[[:>:]]\''; } In the first code, first it checks $value1 and then $value2 one by one, and that way it checks if both of them contain all the words that are put in the search field. What I need is to check if all the words that are put in the search field are contained in the one OR in the another. I want to make it search through both of them at the same time, but I don't know how to put correctly that OR I put in the second example. So any professional help will be appreciated. Here is an example of what I mean: If the Ad has this: Ad Title: nokia phone on sale Ad Description: brand new, unpacked, with 16gb memory card included. and if someone searches for nokia sale it will show the ad, because all the search words are contained in the Ad Title. Also, if the search is brand unpacked it will also show the ad, because all the search words are contained in the Ad Description. But, the problem is if someone searches for nokia brand This way, the word nokia is not contained in the Ad Description, and the word brand is not contained in the Ad Title, so the ad will not be shown. So, I only need a way to put that OR correctly to connect those two values, just like the second code, but in the right way. Thanks in advance. I cant seem to get these two forms to basically work together.....I need this code(a form submit): Code: [Select] <?php // Where the file is going to be placed $target_path = "uploads/public/uploads/admin/u1p2l3o4a5d6s789/98437e10ec5605a849c3bd9641494560_/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> with this code: Code: [Select] <?php if(isset($_POST['save'])) { $event = $_POST['event']; $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; $description = $_POST['description']; $location = $_POST['location']; $month = $_POST['month']; $title1 = $_POST['title1']; $title2 = $_POST['title2']; $title3 = $_POST['title3']; $title4 = $_POST['title4']; $title5 = $_POST['title5']; $title6 = $_POST['title6']; $title7 = $_POST['title7']; $title8 = $_POST['title8']; $date1 = $_POST['date1']; $date2 = $_POST['date2']; $date3 = $_POST['date3']; $date4 = $_POST['date4']; $date5 = $_POST['date5']; $date6 = $_POST['date6']; $date7 = $_POST['date7']; $date8 = $_POST['date8']; $subevent1 = $_POST['subevent1']; $subevent2 = $_POST['subevent2']; $subevent3 = $_POST['subevent3']; $subevent4 = $_POST['subevent4']; $subevent5 = $_POST['subevent5']; $subevent6 = $_POST['subevent5']; $subevent7 = $_POST['subevent6']; $subevent8 = $_POST['subevent7']; $price1 = $_POST['price1']; $price2 = $_POST['price2']; $price3 = $_POST['price3']; $price4 = $_POST['price4']; $price5 = $_POST['price5']; $price6 = $_POST['price6']; $price7 = $_POST['price7']; $price8 = $_POST['price8']; $month2 = $_POST['month2']; $month_num = $_POST['month_num']; $day = $_POST['day']; $year = $_POST['year']; $shutoff = $_POST['shutoff']; if(!get_magic_quotes_gpc()) { $event = addslashes($event); $startdate = addslashes($startdate); $enddate = addslashes($enddate); $description = addslashes($description); $location = addslashes($location); $month = addslashes($month); $title1 = addslashes($title1); $title2 = addslashes($title2); $title3 = addslashes($title3); $title4 = addslashes($title4); $title5 = addslashes($title5); $title6 = addslashes($title6); $title7 = addslashes($title7); $title8 = addslashes($title8); $date1 = addslashes($date1); $date2 = addslashes($date2); $date3 = addslashes($date3); $date4 = addslashes($date4); $date5 = addslashes($date5); $date6 = addslashes($date6); $date7 = addslashes($date7); $date8 = addslashes($date8); $subevent1 = addslashes($subevent1); $subevent2 = addslashes($subevent2); $subevent3 = addslashes($subevent3); $subevent4 = addslashes($subevent4); $subevent5 = addslashes($subevent5); $subevent6 = addslashes($subevent6); $subevent7 = addslashes($subevent7); $subevent8 = addslashes($subevent8); $price1 = addslashes($price1); $price2 = addslashes($price2); $price3 = addslashes($price3); $price4 = addslashes($price4); $price5 = addslashes($price5); $price6 = addslashes($price6); $price7 = addslashes($price7); $price8 = addslashes($price8); $month2 = addslashes($month2); $month_num = addslashes($month_num); $year = addslashes($year); $day = addslashes($day); } include 'config.php'; include 'opendb.php'; $query = "INSERT INTO Registration (event, startdate, enddate, description, location, month, title1, title2, title3, title4, title5, title6, title7, title8, date1, date2, date3, date4, date5, date6, date7, date8, subevent1, subevent2, subevent3, subevent4, subevent5, subevent6, subevent7, subevent8, price1, price2, price3, price4, price5, price6, price7, price8, month2, shutoff) VALUES ('$event', '$startdate', '$enddate', '$description', '$location', '$month', '$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$date1', '$date2', '$date3', '$date4', '$date5', '$date6', '$date7', '$date8', '$subevent1', '$subevent2', '$subevent3', '$subevent4', '$subevent5', '$subevent6', '$subevent7', '$subevent8', '$price1', '$price2', '$price3', '$price4', '$price5', '$price6', '$price7', '$price8', '$month2', '$shutoff')"; mysql_query($query) or die('Error, query failed'); include 'closedb.php'; echo "<pre>".print_r($_POST, true)."</pre>"; } ?> I tried this: Code: [Select] <?php if(isset($_POST['save'])) { $event = $_POST['event']; $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; $description = $_POST['description']; $location = $_POST['location']; $month = $_POST['month']; $title1 = $_POST['title1']; $title2 = $_POST['title2']; $title3 = $_POST['title3']; $title4 = $_POST['title4']; $title5 = $_POST['title5']; $title6 = $_POST['title6']; $title7 = $_POST['title7']; $title8 = $_POST['title8']; $date1 = $_POST['date1']; $date2 = $_POST['date2']; $date3 = $_POST['date3']; $date4 = $_POST['date4']; $date5 = $_POST['date5']; $date6 = $_POST['date6']; $date7 = $_POST['date7']; $date8 = $_POST['date8']; $subevent1 = $_POST['subevent1']; $subevent2 = $_POST['subevent2']; $subevent3 = $_POST['subevent3']; $subevent4 = $_POST['subevent4']; $subevent5 = $_POST['subevent5']; $subevent6 = $_POST['subevent5']; $subevent7 = $_POST['subevent6']; $subevent8 = $_POST['subevent7']; $price1 = $_POST['price1']; $price2 = $_POST['price2']; $price3 = $_POST['price3']; $price4 = $_POST['price4']; $price5 = $_POST['price5']; $price6 = $_POST['price6']; $price7 = $_POST['price7']; $price8 = $_POST['price8']; $month2 = $_POST['month2']; $month_num = $_POST['month_num']; $day = $_POST['day']; $year = $_POST['year']; $shutoff = $_POST['shutoff']; if(!get_magic_quotes_gpc()) { $event = addslashes($event); $startdate = addslashes($startdate); $enddate = addslashes($enddate); $description = addslashes($description); $location = addslashes($location); $month = addslashes($month); $title1 = addslashes($title1); $title2 = addslashes($title2); $title3 = addslashes($title3); $title4 = addslashes($title4); $title5 = addslashes($title5); $title6 = addslashes($title6); $title7 = addslashes($title7); $title8 = addslashes($title8); $date1 = addslashes($date1); $date2 = addslashes($date2); $date3 = addslashes($date3); $date4 = addslashes($date4); $date5 = addslashes($date5); $date6 = addslashes($date6); $date7 = addslashes($date7); $date8 = addslashes($date8); $subevent1 = addslashes($subevent1); $subevent2 = addslashes($subevent2); $subevent3 = addslashes($subevent3); $subevent4 = addslashes($subevent4); $subevent5 = addslashes($subevent5); $subevent6 = addslashes($subevent6); $subevent7 = addslashes($subevent7); $subevent8 = addslashes($subevent8); $price1 = addslashes($price1); $price2 = addslashes($price2); $price3 = addslashes($price3); $price4 = addslashes($price4); $price5 = addslashes($price5); $price6 = addslashes($price6); $price7 = addslashes($price7); $price8 = addslashes($price8); $month2 = addslashes($month2); $month_num = addslashes($month_num); $year = addslashes($year); $day = addslashes($day); } include 'config.php'; include 'opendb.php'; $query = "INSERT INTO Registration (event, startdate, enddate, description, location, month, title1, title2, title3, title4, title5, title6, title7, title8, date1, date2, date3, date4, date5, date6, date7, date8, subevent1, subevent2, subevent3, subevent4, subevent5, subevent6, subevent7, subevent8, price1, price2, price3, price4, price5, price6, price7, price8, month2, shutoff) VALUES ('$event', '$startdate', '$enddate', '$description', '$location', '$month', '$title1', '$title2', '$title3', '$title4', '$title5', '$title6', '$title7', '$title8', '$date1', '$date2', '$date3', '$date4', '$date5', '$date6', '$date7', '$date8', '$subevent1', '$subevent2', '$subevent3', '$subevent4', '$subevent5', '$subevent6', '$subevent7', '$subevent8', '$price1', '$price2', '$price3', '$price4', '$price5', '$price6', '$price7', '$price8', '$month2', '$shutoff')"; mysql_query($query) or die('Error, query failed'); include 'closedb.php'; echo "<pre>".print_r($_POST, true)."</pre>"; $target_path = "uploads/public/uploads/admin/u1p2l3o4a5d6s789/98437e10ec5605a849c3bd9641494560_/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } ?>but it didn't work..... Would there be any feasible way of combining the two Update statement below into one? The Members Table has id, username, password, and application_id The Application Table has the application id, the users application information and whether or not the application is approved. if($_GET['approved']=="update"){ $approved=$_GET['approved']; $approved=sanitize($approved); if($approved=="y"){ $id=(int)$_GET['id']; $username=$_GET['username']; $username=sanitize($username); $password=$_GET['password']; $password=sanitize($password); $approved_sql='UPDATE members SET username="$username" password="$password" application_id="$id"'; $approved_result=mysql_query($approved_sql); $approved_rows=mysql_affect_rows(); $update_approved_sql='UPDATE application SET approved="y" WHERE id="$id"'; $update_approved_result=mysql_query($update_approved_sql); $update_approved_rows=mysql_affect_rows(); if($approved_rows==1 && $update_approved_rows==1{ header("Location: ./index.php??admincp=investors&view=applications&id=1&approved=updated"); } } } |