-
Posts
24,599 -
Joined
-
Last visited
-
Days Won
828
Everything posted by Barand
-
alternative method $db = new mysqli(HOST, USERNAME, PASSWORD, 'metrocellars'); $sql = "SELECT l.location , r.region , w.winery_name , w.url , p.label FROM location l INNER JOIN region r USING (lid) INNER JOIN product p USING (rid) INNER JOIN winery w USING (pid) INNER JOIN varietal v USING (vid) WHERE lid = 2 ORDER BY r.region, w.winery_name, v.varietal "; $prevRegion = $prevWinery = ''; $res = $db->query($sql); while (list($loc,$rgn, $wnry, $url, $label) = $res->fetch_row()) { if ($prevRegion != $rgn) { echo "<h3>$rgn</h3>\n"; $prevRegion = $rgn; $prevWinery = ''; } if ($prevWinery != $wnry) { echo "<a href='$url'>$wnry</a><br>\n"; $prevWinery = $wnry; } echo "<span style='margin-left:15px;'>$label</span><br>\n"; }
-
`word` = 'a' OR `word` = 'b' OR `word` = 'c' OR `word` = 'ab' OR `word` = 'ac' OR `word` = 'ba' OR `word` = 'ca' OR `word` = 'cb' OR `word` = 'abc' OR `word` = 'cba' OR `word` = 'bca' */ can be simplified to `word` IN ('a', 'b', 'c', 'ab', 'ac', 'ba', 'ca', 'cb', 'abc', 'cba', 'bca')
-
$to is given a value early on in the code only if certain conditions are true. I you later try to output when those conditions are not true then it will be undefined.
-
You need to escape $img_src as it contains quotes. mysql_real_escape_string
-
I have just told you the solution
-
that only proves that the string value "../backend/playlist_form.php" exists
-
put $img_src in single quotes, not backticks. (Backticks say "this is a column name")
-
realpath will just return false if the path/file does not exist
-
Don't assign the $result['isProcessed'] back to $result. $processed = $result['isProcessed'] ? 'yes' : 'n/a'; echo "<td>$processed</td>";
-
Where to store sensitive client details (MYSQL DB credentials)
Barand replied to Neji's topic in PHP Coding Help
According to the MySQL manual: Note The PASSWORD() function is used by the authentication system in MySQL Server; you should not use it in your own applications. For that purpose, consider MD5() or SHA1() instead. Also see RFC 2195, section 2 (Challenge-Response Authentication Mechanism (CRAM)), for more information about handling passwords and authentication securely in your applications. -
I had a look at your elso1.php output and I'm puzzled why the column headings are out of sequence. Did you use the latest version I posted that has the natsort() included?
-
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?