-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
adding to an array with each recursive function
Barand replied to 1internet's topic in PHP Coding Help
Here's a simple example of a recursive function writing to an array $results = array(); function gatherResults($var, &$results) { $results[] = $var; if ($var >= 10) return; // terminate the recursion gatherResults($var+1, $results); } $var = 1; gatherResults($var, $results); echo '<pre>',print_r($results, true),'</pre>'; -
Easiest way to generate a range of date is to use DateTime and DatePeriod objects $timestampS = strtotime('2013-06-01'); // create unix timestamps $timestampE = strtotime('2013-06-14'); $dt1 = new DateTime(); $dt1->setTimestamp($timestampS); $dt2 = new DateTime(); $dt2->setTimestamp($timestampE); $dt2->modify('+1 days'); // increment to include last day in the date period //create datePeriod object $dp = new DatePeriod($dt1, new DateInterval('P1D'), $dt2); // loop through the dates in the datePeriod foreach ($dp as $date) { // these are the dates to enter in the database echo $date->format('Y-m-d') . '<br>'; } /* results *************************** 2013-06-01 2013-06-02 2013-06-03 2013-06-04 2013-06-05 2013-06-06 2013-06-07 2013-06-08 2013-06-09 2013-06-10 2013-06-11 2013-06-12 2013-06-13 2013-06-14 **************************************/
-
Good luck
-
can you post the output from this code echo'<pre>'; var_export($option); echo '</pre>';
-
Your data tables do not reflect that structure, it is more like country--+--> area | +--> region | +--> destination ----> rates <----- airline
- 2 replies
-
- php help
- seach form
-
(and 1 more)
Tagged with:
-
HTML syntax for a table is <table> <tr> <td> name1 </td> <td> qty1 </td> </tr> <tr> <td> name2 </td> <td> qty2 </td> </tr> </table> so put the data items inside <td>...</td> cells
-
Now you have added the hidden field, $_POST['wallbox'] is always set, that's why it is always yes. You now need to check if it is equal to 1 instead of checking isset()
-
You need to avaoid running queries inside loop as it kills performance. My version uses a single query to get all the required data. It stores the discount values in an array which output on change of product then cleared ready for the next set of product data. The keys of the array are the disp_values which are stored in a pre-created blank array. This the mysql version // // GET DISP_VALUES FOR HEADINGS // $sql = "SELECT DISTINCT disp_value FROM option_choices"; $res = mysql_query($sql); $blank_discounts = $vals = array(); $output = "<tr><th>Product</th><th>Price</th><th>"; while ($row = mysql_fetch_row($res)) { $vals[] = $row[0]; } // ensure values in correct order natsort($vals); $output .= join('</th><th>', $vals) . "</th></tr>\n"; $blank_discounts = array_fill_keys($vals,'0.000'); // // CREATE THE PRICING GRID // $current_prod = ''; $current_price = 0; $sql = "SELECT product_name, default_price, disp_value, percentage FROM product INNER JOIN product_options USING (product_ID) INNER JOIN option_choices USING (option_number) ORDER BY default_price"; $res = mysql_query($sql); while (list($prod, $price, $disp, $pc) = mysql_fetch_row($res)) { if ($current_prod != $prod) { if ($current_prod) { // on change of product output array of discounts $output .= "<tr><td>$current_prod</td><td>$current_price</td>"; foreach ($prod_discounts as $disc) { $output .= "<td>$disc</td>"; } $output .= "</tr>\n"; } $current_prod = $prod; $current_price = $price; $prod_discounts = $blank_discounts; } $prod_discounts[$disp] = number_format($pc,3); } // output array of dicounts for final product $output .= "<tr><td>$current_prod</td><td>$current_price</td>"; foreach ($prod_discounts as $disc) { $output .= "<td>$disc</td>"; } $output .= "</tr>\n"; ?> <table border="1" cellpadding="4"> <?php echo $output ?> </table>
-
Set the value before outputting the table $isWallboxPatchReqd = isset($_REQUEST['wallbox']) ? 'yes' : 'no'; .... echo "<td>$isWallboxPatchReqd</td>"; ....
-
String values in a query need to be quoted thus '$isWallboxPatchReqd', otherwise sql assumes they are column names
-
I showed you how in your similar post yesterday http://forums.phpfreaks.com/topic/279073-checkbox-values/?do=findComment&comment=1435557
-
If you want the field to remain null when it is blank exclude it from the update so you do not provide a value.
-
dates('s') has a value range of 0 - 59. It is the seconds element of the time display.
-
What is in $_FILES['file']['type'] ? What does $_FILES['file']['tmp'] contain?
-
Export data from multiple databases with one single select statement
Barand replied to michaeljdornan's topic in MySQL Help
It reads that as ziguana_cystic minus fibrosis.Profiles. Use backticks (or don't use hyphens) `ziguana_cystic-fibrosis`.Profiles -
You only need call the function for displayed comments - You aren't planning on displaying 50.000 at a time, are you?
-
I suspect you data model isn't fully normalized Winery (pid) 2 is always in region 4 so you don't need pid and rid in the product table. location | +-------< region | +-----------< winery varietal | | +-------< product >----------+
-
Use DateTime and DateInterval objects. $timestamp = '2013-06-13 01:00:00'; $dt = new DateTime($timestamp); $diff = $dt->diff(new DateTime())->format('%y,%m,%d,%h,%i,%s'); list ($y, $m, $d, $h, $n, $s) = explode(',', $diff); edit: result $diff = 0,0,0,0,39,5
-
Question about a query I thought would be a lot simpler!
Barand replied to jbradley04's topic in MySQL Help
For your first requirement you need to construct a query with this WHERE clause WHERE (col LIKE '%d%') OR (col LIKE '%r%') OR (col LIKE '%e%') OR (col LIKE '%a%') For the second, replace the OR with AND -
Trying to display data from databse in a php table
Barand replied to BrainBoxMad's topic in PHP Coding Help
Give us a clue. How do you want it to appear? -
After running the query, what does mysql_error() tell you?
-
First you complain about duplicates then you say they can be duplicated. I'm out of here.
-
If I were you I'd stick with a tinyint with values 0 or 1. However, if you want 'Yes' or 'No' (which then gives complications of testing for ' yes' or 'Yes' ) then $wallboxReqd = isset($_REQUEST['wallbox']) ? 'yes' : 'no'; and you will need to change the field type in the db table
-
New rows not working, overwriting last entry in cell.
Barand replied to FrankieGee's topic in PHP Coding Help
Sorry, I just copied your name= bit and didn't spot the $ in the name. Try echo "<input type=\"checkbox\" name=\"item_no[]\" value=\"$item_no\" />$item_no $ihddescr_1<br />"; Your selected item numbers will be in the array $_POST['item_no']