PHP - How To Pass Array To New Window Without Form
I am working on search result page where all the thumbnail will display and its working fine.
but what my boss wants is when user click on any thumbnail a new window will open with the product image and next and prev button so that user will navigate search result through new window so how i can pass all the ID to new window so that this funtionality can be done thanks in advance.. Similar TutorialsHi, I'm trying to pass values from an array into a form. As a newbie, I've came up with the code underneath, but I want to pinpoint all the first values toward 1 selection list in the form. Any suggestions how to accomplish this? Thanks in advance. Ruud <html> <head> <title>Test formulier</title> </head> <body> <h2>Test formulier</h2> <form action="test.php" method="post"> <p> <?php $prijzen = array( array("01", "125","150", "A" => true,"B" => true), array("02", "125","150", "A" => true,"B" => true), array("03", "125","150", "A" => true,"B" => false), array("04", "125","150", "A" => true,"B" => true) ); ?> </P> <select name="prijzen[]" id="prijzen" multiple="multiple" size="7" class="none"> <?php while(list($key, $val) = each($prijzen)){ while(list($key2, $val2) = each($val)){ echo '<option value="'.$key2.'">'.$val2.'</option>'.PHP_EOL; } } ?> </select> </body> </html> hey guys,i'm back with a new prob.. i have an image here that when clicked using onclick, will open a window and sort of pass the php values to the window. okay,it's confusing but perhaps this will help you understand. let me break it down. this is what the image code looks like. i have placed this inside the php echo. Code: [Select] <img src="images/edit.png" alt="Edit rooms" width="16" height="16" onclick="window.open(\'edit.php?course='.$row['c_name'].'&year='.$row['year'].'&block='.$row['block'].'\',\'width=300, height=200, menubar=yes\')"/> now my problem is i can't seem to get all three of the values, c_name,year and block to be posted on the window.. here's the code on edit.php: Code: [Select] <?php include("dbcon.php"); $course = $_GET['c_name']; $year = $_GET['year']; $block = $_GET['block']; ?> <html> <body> Course:<input type="text" name="course" value="<?php echo $course;?>"><br> Year:<input type="text" name="year" value="<?php echo $year;?>"><br> Block:<input type="text" name="block" value="<?php echo $block;?>"><br></html> i have already used $_GET as you can see but only year and block appear on the form. i get a notice saying that c_name is an undefined index. i am really confused and i don't know what the problem is. i hope you guys can help me.. Hi I am looking to be able to pass an array to mysql_fetch_row() not sure where i am going wrong. works fine like this. Code: [Select] mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); while ($row = mysql_fetch_array($new)) { echo $row['username'] . $DELIMITER . $row['firstname'] . $DELIMITER . $row['lastname'] . $DELIMITER . $row['password'] . $DELIMITER. "example@gmail.com" . $DELIMITER . "author"; echo "<br />"; } But really need too be able to do it this way. Code: [Select] mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); echo "<pre>"; //print_r($row); echo "</pre>"; $sam = array('username','firstname','lastname'); while ($row = mysql_fetch_row($new)) { echo $row[$sam] . $DELIMITER; echo "<br />"; } So it will just loop through the array so i can keep adding to it by just adding an extra parameter to the array. Any Help Stuck???? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347360.0 I want the quiz questions a teacher loads to be randomized so that each time the teacher gives it (different class, different day, whatever …) the order of questions will be randomized. I'm loading the data into an array and then shuffling it. Problem solved. BUT … students on their smart devices need to load the same quiz with the same question order.
I can solve this by:
- teacher stores question and answer data and order temporarily in a dB table
- students load that information
- problem solved
But I was hoping to do this without using a table. Is there a way to pass a randomized array from the teacher to the students without going through a dB table? Thanks.
I have a simple ajax that passes data to a php script using jquery serialize. This is working good but where I am getting stuck is trying to pass json array into mysql. The json is outputting the correct data, but when I insert into db, it just says Array in the field. How can I convert(if that is the right term) json array to use in mysql. In the code I have posted, $box is an array from jquery which I normally use foreach to loop through array. What I need to do is convert $box after is has been encoded. Thanks Code: [Select] $box = $_POST['BRVbrtrv_boxnumber']; $list = array("activity" => $activity, "mobile" => $mobile, "company" => $company, "authorised" => $authorised, "service" => $service, "department" => $department, "address" => $address, "boxcount" => $boxcount, "box" => $box); $c = json_encode($list); echo $c; Hello All, I have used a function to collect a users information from the database. This is then returned as an array. Using this returned array, I wish to pass it into another function. Here is the code: The array is created in the collect() function and needs to be passed to the ipn_data function Code: [Select] /* This script is responsible for handling all subscription payments. It will collect all information, insert data into the relevant databases and then forward the user to PayPal with the relevant transaction ID. On return, the IPN listener will deal with all account changes whilst the user is held in a queue. */ /* ------------------------------------- */ /* DATABASE CONFIGURATION */ /* ------------------------------------- */ include_once "../config/config.php"; /* ------------------------------------- */ /* COLLECT SESSION INFORMATION */ /* ------------------------------------- */ session_start(); $id = "100000002"; // ID of logged in user $next_year = date("Y-m-d", strtotime("+365 day", time())); //Date next year /* ------------------------------------- */ /* SET VARIABLES */ /* ------------------------------------- */ $reason = $_GET["reason"]; /* ----------------------------------------- */ /* COLLECT USERS INFORMATION FROM DATABASE */ /* ----------------------------------------- */ function collect($id) { //Select the subscriber from the database $query = "SELECT * FROM subscribers WHERE id='$id'"; $query = mysql_query($query); //Collect the subscribers first name, last name and email address while($row=mysql_fetch_array($query)) { $fname = $row["fname"]; $lname = $row["lname"]; $email = $row["email"]; } //Collate subscribers information into an array return array('fname' => "$fname", 'lname' => "$lname", 'email' => "$email"); } /* ----------------------------------------- */ /* CREATE TIMESTAMP OF CURRENT TIME */ /* ----------------------------------------- */ function mktimestamp() { //Set date variables $day = date("d"); $month = date("m"); $year = date("Y"); //Make timestamp return mktime(0, 0, 0, $month, $day, $year); } /* ----------------------------------------- */ /* INSERT USERS DATA INTO ipn_data */ /* ----------------------------------------- */ //Create random identifier $ident = rand("1", "10000"); function ipn_data($info, $reason, $timestamp) { //WANT THE ARRAY TO BE PASSED INTO HERE!! //I TRIED PASSING THE $info VARIABLE INTO THE FUNCTION, WHICH IS WHAT I ASSIGNED TO THE COLLECT FUNCTION LATER IN THE SCRIPT } /* ----------------------------------------- */ /* Get ID of inserted ipn_data row */ /* ----------------------------------------- */ function get_id($ident, $timestamp) { //Setup Query to find ID $query = "SELECT * FROM subscribers WHERE timestamp='$timestamp' AND identifier='$ident'"; //Run Query $query = mysql_query($query) or mysql_error(); //Using query find ID while($row=mysql_fetch_array($query)) { $ltj_txn_id = $row["id"]; } return $ltj_txn_id or mysql_error(); } /* ------------------------------------- */ /* SWITCH REASON */ /* ------------------------------------- */ switch($reason) { case "subscribe": break; case "renew": //Collect array from user information array function $info = collect($id); //Get timestamp from our mktimestamp function $timestamp = mktimestamp(); //Insert users data into ipn_data table $run_ipn = ipn_data($reason, $timestamp, $ident); //Collect ID of record just inserted $get_id = get_id($ident, $timestamp); echo "$run_ipn"; break; case "upgrade": break; default: break; } Any ideas? In my view file, I instantiate User class and call two methods that have not been declared or initialized in the class: $user = new Models\User(); $user->setFirstName('John'); $user->setLastName('Merlino'); echo $user->getFirstName() . " " . $user->getLastName(); However, I have two private members only available to instances: protected $first_name; protected $last_name; Because I don't want to manually create privileged getters and setters for each of my private members, I use the call method: public function __call($name,$args){ echo $name . "<br />"; echo $args . "<br />"; } Because my methods were not initialized, the interpreter calls the __call method as a last option resort, and passes the name of the method in local variable $name and if exists the arguments passed into the method in local variable $args. Ok so that makes sense. However, when I echo the values of the two variables, I see a blank array created: setFirstName Array setLastName Array getFirstName Array getLastName Array See everytime I call it, there's an array being created. I don't see the purpose of this. Also how often do you use __call() in your php applications, specifically when using MVC? Thanks for response. I am simply trying to insert a value generated from an array in a while loop, but it seems the value is not global and I can't pass it as I like. I did some research on this, but could not find an answer that solved my issue... Here is my select box code which is working perfect: <select name="city"> <?php $sql = "SELECT id, city_name FROM cities ". "ORDER BY city_name"; $results_set = (mysqli_query($cxn, $sql)) or die("Was not able to produce the result set!"); while($row = mysqli_fetch_array($results_set)) { echo "<option value=$row[id]>$row[city_name]</option>"; } ?> </select> Are any variables defined in a while loop global to the while loop only? Here is my SQL which you can see my $row[id] being passed thru field city_id... The value is being generated as supposed to based on value like: value="1", value="2" etc.. for the select options for each city name. So the values are there... But I CANNOT get that numerical id to pass to the database when submitting my form. Any ideas for a workaround to get this value passing as normal? if (isset($_POST['addPosting'])) { $query = "INSERT INTO Postings (id, city_id, title, description) VALUES ('','$row[id]','$_POST[title]','$_POST[description]')"; /* Output of the table will display the Suite based on the distinct date. The pass rate percentage calculate based on the Suite1 and app1 and the specific date. For example at Apr 4 2011, I need to Sum the total passcount,failcount,errorcount of Bluetooth, GPSA, EMIReceiver($app1) of XA9 on Real MXE($suite1) , then calculate the passrate percentages. But I fail to get the correct value of the passcount, failcount, errorcount value.Helps! Output of the table suite Date Percentages(pass rate) XA9 on Real MXE Apr 4 2011 9:47AM 99.94% XA9 on Real MXE Apr 5 2011 10:48AM 99.94% XA9 on Real MXE Apr 6 2011 9:49AM 99.95% XA9.5 on Real EXA_B40 Apr 4 2011 7:06AM 99.94% XA9.5 on Real EXA_B40 Apr 5 2011 7:14AM 99.93% XA9.5 on Real EXA_B40 Apr 6 2011 7:29AM 99.93% */ $suite1 --> array value (XA9 on Real MXE, XA9.5 on Real EXA_B40) $app1 --> array value (Bluetooth, GPSA, EMIReceiver) if(is_array($suite_type1)){ foreach($suite_type1 as $suite1) { $sql222="Select Distinct a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$fromdate' and a.StopDTTM<='$to_date' and a.SuiteFilePath like '%$Program%' and a.SuiteFileName='$suite1'"; $result222=mssql_query($sql222,$connection) or die("Failed Query of".$sql222); while($row222 = mssql_fetch_array($result222)) { $datetotest = $row222[0]; $days_to_add = 1; $tilldate = fnc_date_calc($datetotest,$days_to_add); //Query the result based on the date $sql223="Select Distinct a.SuiteFileName, a.SuiteID,a.StopDTTM from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like'%$Program%' and a.SuiteFileName='$suite1' order by a.StopDTTM"; $result223=mssql_query($sql223,$connection) or die("Failed Query of".$sql223); while($row223 = mssql_fetch_row($result223)){ foreach($app_type1 as $app1) { $sql3="Select Sum(b.passcount),Sum(b.failcount),Sum(b.errorcount) from Suite a,Test b where a.SuiteID=b.SuiteID and b.SuiteID=a.SuiteID and a.StopDTTM>='$row222[0]' and a.StopDTTM<='$tilldate' and a.SuiteFilePath like '%$program%' and a.SuiteFileName = '$suite1' and b.Product='$app1'"; $result3=mssql_query($sql3,$connection) or die("Failed Query of ". $sql3); $row3 = mssql_fetch_row($result3); $total_passcount+=$row3[0]; $total_failcount+=$row3[1]; $total_errorcount+=$row3[2]; } $overall_total=$total_passcount+$total_failcount+$total_errorcount; echo "<tr>"; echo "<td><a href='detailsreport.php?suiteID=".$row223[1]."&suitetype=".$row223[0]."&fromdate=".$fromdate."&to_date=".$to_date."&date=".$row222[0]."&tilldate=".$tilldate."&SuiteFilePath=".$Fprogram."'>" . $row223[0] . "</a></td>"; //Suite File Name echo "<td>" . $row223[2] . "</td>"; //Pass percentage if($total_passcount>0){ echo "<td bgcolor=00FF33>" . number_format((($total_passcount/$overall_total)*100),2)."%</td>"; } else{ echo "<td bgcolor=00FF33>0%</td>"; } } } } echo "</table>"; } Hello, I want to use this function in form. How can I pass parameter in form ? please help me. Thanks <?php function displayName($fetch) { echo "your Name is ".$fetch; } ?> I have a purchase order displaying on a site that the user can edit quantities for. I want them to be able to hit submit and it takes that form and submits it to some code that auto creates a PDF with it. The PDF part is easy, I use DOMPDF to create that and it works fine, I just can't seem to get the values passed through. I can easily pass the values of just the input boxes through the $_POST but I don't want to have to recreate the PDF setup after the post. I'd rather just use some Javascript or something to grab the innerHTML of a <div> element and somehow make it available after the form is submitted so the PHP code can use it to send to DOMPDF. The form submits to itself and I have a piece of code at the top of the page which will create the PDF, I just need the <div> contents and I'm done. How do I get it? I could set it into a hidden variable but the reason I'm not doing that is because for some reason when I assign the big table which contains the whole purchase order into the hidden variable and then try to print it, it comes out all messed up. I don't know why and I'd rather just find another way than attempt to figure that out. Currently I have a PHP file that is pulling information from a table in the Database and inserting it into an HTML table. It consists of the fields: Last_Name, First_Name, Party, District, Address, CIty, State, Zip, and Email. And the Email field is being converted to a Hyperlink. (All working fine so far) I also have a form that has a prewritten letter to be sent to the email address. I need to have the HyperLink from the Email pass the address to the form to allow me to send it. I am not sure how to get this to happen. Here is the code I have so far: The pull from the database: <?php $dbhost = 'localhost'; $dbuser = 'removed'; $dbpass = 'removed'; $db = 'removed'; $link = mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error()); mysql_select_db($db)or die(mysql_error()); $result = mysql_query("SELECT * FROM 2011members") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Last Name</th> <th>First Name</th> <th>Party</th> <th>District</th> <th>Address</th> <th>City</th> <th>State</th> <th>Zip</th> <th>Email</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Last_Name']; echo "</td><td>"; echo $row['First_Name']; echo "</td><td>"; echo $row['Party']; echo "</td><td>"; echo $row['District']; echo "</td><td>"; echo $row['Address']; echo "</td><td>"; echo $row['City']; echo "</td><td>"; echo $row['State']; echo "</td><td>"; echo $row['Zip']; echo "</td><td>"; //Normal Pull //echo $row['Email']; //echo "</td><td>"; //Just Hyperlink //echo '<a href="http://',Email,'">',Email,'</a>'; //echo "</td></tr>"; echo '<a href="http://'.$row['Email'].'">'.$row['Email'].'</a>'; echo "</td></tr>"; } echo "</table>"; ?> The Form: Code: [Select] <?php if($_POST){ $to = 'becca@windfallstudio.com'; $subject = "WHAT SHOULD THIS BE"; $message = "Date: $date\n\r". "Dear $legislator,\n\r". "As a constituent of yours, I urge you to closely review $bill as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.\n\r". "Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.\n\r". "Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)\n\r". "Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.\n\r". "While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.\n\r". "Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.\n\r". "Sincerely,\n".u "$name \n". "$street \n". "$city, $zip \n". "$email \\n". $headers = "From: $email"; mail($to, $subject, $message, $headers); // SUCCESS! echo '<p class="notice">'. 'Thank you for your submission. '. '</p>'; // clear out the variables for good-housekeeping unset($date,$legislator,$bill,$name,$street,$city,$zip,$email); $_POST = array(); } ?> <div id="content" class="section"> <?php arras_above_content() ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php arras_above_post() ?> <div id="post-<?php the_ID() ?>" <?php arras_single_post_class() ?>> <?php arras_postheader() ?> <div class="entry-content clearfix"> <form method="post" action="" id="letter"> <p><label for="name">Date</label> <input type="text" name="date" id="date" value="<?php echo $_POST['date'];?>"/></p> <p>Dear Senator/Representative <select name="legislator"> <option>Choose a Legislator</option> <option>Senator John Q. Public</option> <option>Rep. Jane Q. Public</option> <option>Some Third Person</option> </select>,</p> <p>As a constituent of yours, I urge you to closely review Bill <select name="bill"> <option>Choose a Bill</option> <option>SB 13 / LC0448</option> <option>LC0505</option> <option>LC0532</option> </select> as it pertains to the distribution and allotment of the 4 percent bed tax collected at lodging properties in Montana.</p> <p>Tourism is very important to Montana. Not only it is the second largest industry in Montana, it is also a key economic engine for businesses and the thousands of Montanans that have jobs because of tourism.</p> <p>Nearly 10 million visitors travel to our state each year, contributing between $2.4 billion and $3 billion annually into our economy. In addition to bringing new money into our state, these visitors also help support more than 42,000 Montana jobs and $897 million in worker salaries. (Source: Montana Office of Tourism Annual Report - 2010)</p> <p>Please rest assured that these millions of visitors don't come on their own. They are enticed to come here through marketing and outreach done by various organizations that include the Montana Office of Tourism, Glacier Country Regional Tourism Commission and Missoula Convention and Visitor Bureau.</p> <p>While there is a 7 percent bed tax collected at all lodging entities in the state, 3 percent supports the General Fund and 4 percent supports travel-related partners. The 4 percent is vital to marketing our stage and it is imperative for that money to remain solely dedicated to travel and tourism promotion. I would urge you to vote no on any bill that would direct any portion of that 4 percent elsewhere.</p> <p>Thank you for your consideration in this request and for doing all you can to represent us, your constituents, to the best of your ability. I look forward to hearing from you soon.</p> <p>Sincerely,<br /> <label for="name">Name:</label> <input type="text" name="name" id="name" value="<?php echo $_POST['name'];?>"/><br /> <label for="email">Street:</label> <input type="text" name="street" id="street" value="<?php echo $_POST['street'];?>"/><br /> <label for="email">City:</label> <input type="text" name="city" id="city" value="<?php echo $_POST['city'];?>"/><br /> <label for="email">Zip:</label> <input type="address" name="zip" id="zip" value="<?php echo $_POST['zip'];?>"/><br /> <label for="email">E-mail:</label> <input type="text" name="email" id="email" value="<?php echo $_POST['email'];?>"/></p> <input type="submit" class="button" value="Submit" /> </form> <?php the_content( __('<p>Read the rest of this entry »</p>', 'arras') ); ?> <?php wp_link_pages(array('before' => __('<p><strong>Pages:</strong> ', 'arras'), 'after' => '</p>', 'next_or_number' => 'number')); ?> </div> What do I need to do to get the Email link from the HTML table to pass to the Email variable in the Form? On an HTML Form, I have several Text boxes called "base1, base2...base13" Another text box I have is called "base_quantity" In my PHP routine: This is part of my code: Code: [Select] $selected_base = $_POST['base1']; if ($selected_base == 'yes') { $base_value = $base_value + 1; $base_status = 'Yes'; } else if ($selected_base == 'no') { $base_value = $base_value - 1; $base_status = 'No'; }Later on in the PHP routine I want to pass back to the Form the value of $base_status and place it in the "base_quantity" text box. Something like this: base_quantity = $base_value. Can someone tell me how information is passed back to the FORM. Thank You, Sam I'll be having .txt files uploaded via a form. Upon submission, it will be passed to another .php file to have the data entered into the database. It's not uploading the file to the folder, and while the trigger echoes what's set up to echo, it's loading the data into the database.
Here is the form: echo '<form action="/wp-content/plugins/csi_stats/csi_process.php" method="post" enctype="multipart/form-data"> Select Boxscore to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload" name="submit"> </form>'; } Here is csi_process.php $filename = $_FILES['fileToUpload']['name']; $target_dir = "/wp-content/uploads/csi_boxscores/21/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { // $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); echo $target_file . ' Boxscore Sent'; echo '<br>' .$filename; $uploadOk = 0; } $query = " LOAD DATA INFILE '$fileName' INTO TABLE a_stats FIELDS TERMINATED BY '|' LINES TERMINATED BY '\r\n' IGNORE 2 Lines (jersey,points,2pm,2pa,3pm,3pa,ftm,fta,oreb,dreb,treb,ast,blk,stl,deflect,turn,charge,pf,tf) SET team = 426"; "team" will ultimately be a variable, and I'll have "game" in there too.
Here is the data: 235a5d12-be10-43af-abba-e45456d9d8da Jersey|Points|TwoPointsMade|TwoPointAttempts|ThreePointsMade|ThreePointAttempts|FreeThrowsMade|FreeThrowAttempts|OffensiveRebounds|DefensiveRebounds|Rebounds|Assists|BlockedShots|Steals|Deflections|Turnovers|Charges|PersonalFouls|TechnicalFouls 10|8|1|2|2|6|0|0|0|4|4|1|1|1|0|1|0|0|0 12|3|0|5|0|3|3|4|1|2|3|0|1|1|0|0|0|2|0 20|8|4|6|0|0|0|0|1|1|2|0|1|1|0|2|0|0|0 22|3|0|1|1|1|0|0|1|2|3|1|0|0|0|2|0|2|0 24|18|4|7|1|3|7|10|0|2|2|1|0|1|0|3|0|3|0 32|1|0|2|0|3|1|2|2|1|3|0|0|1|0|0|0|2|0 41|8|0|0|2|3|2|2|0|0|0|0|0|1|0|0|0|1|0 43|11|5|7|0|0|1|2|0|6|6|1|0|4|0|2|0|3|0 52|3|1|6|0|0|1|1|4|3|7|0|0|1|0|1|0|4|0 Edited November 14, 2020 by Jim R Hello, this question was already answered on this form but the answer was deleted by admin a year or so ago. anyway, I have an edit items page with multiple images and I do not want to have to relocate all of the images manually but if I do not then an empty variable is passed to mysql, thus deleting my image. What do I need to know to write a code that will not pass an empty variable to my table? Do I use sprint? I work with a large codebase and I have this situation come up fairly often:
the legacy class has large objects such as:
$design->motor->dimensions->a; $design->motor->dimensions->bd; $design->specifications->weight; $design->data->height; //etcWhen I create a new class, that class sometimes operates on the specific data, so say: class MyClass { public function compute($weight, $height, $a) { //stuff } } //and I call this for example as such: (new MyClass())->compute($design->specifications->weight, $design->data->height, $design->motor->dimensions->a);CONS: Potential issue: if design specs change and I need to change things parameters in "compute" function, I need to "re-key" the variables I pass to the function, and adjust things accordinly in MyClass as wel. PROS: only the exact data is being passed, and this data can come from anywhere it is viable, so in effect the function is fairly well separated, I think. Alternative option for me is to pass the entire design object, i.e class MyClass { public function compute(&$design) //can also be done via DI through a setter or constructor. { print $design->specifications->weight; print ($design->data->height + $design->motor->dimensions->a); //stuff } } (new MyClass())->compute($design);PROS: In this case when things change internally in which variables are needed and how things are computed, I only need to change the code in compute function of the class itself. CONS: MyClass now needs to be aware of how $design object is constructed. When it comes to this parameter passing, and Dependency Injection like this in general, does Computer Science advocate a preference on this issue? Do I pass the entire object, or do I pass only the bits and pieces I need? I have a form, details getting from customer and calculate the grand total, here how can i pass my grand total value to ccavenue payment gateway page and getting payment form customer? code : https://www.pastiebin.com/5cdbae859bb64 |