Search the Community
Showing results for tags 'loop'.
-
Hi, I am converting an adjacency table to a xml with this code (coming from phpfreaks, thank you Barand!) <?php $data = array( 1 => 0, 2 => 1, 3 => 1, 4 => 2, 5 => 3, 6 => 5 ); echo "<?xml version='1.0' encoding='iso-8859-1'?>\n"; echo "<tree id='0'>\n"; tree(0); echo "</tree>\n"; function tree ($parent, $level=0) { global $data; $children = array_keys($data, $parent); if ($children) foreach ($children as $kid) { $indent = str_repeat("\t", $level+1); echo "$indent<item text='$kid' id='$kid'>\n"; tree($kid, $level+1); echo "$indent</item>\n"; } } ?> Returning <?xml version='1.0' encoding='iso-8859-1'?> <tree id='0'> <item text='1' id='1'> <item text='2' id='2'> <item text='4' id='4'> </item> </item> <item text='3' id='3'> <item text='5' id='5'> <item text='6' id='6'> </item> </item> </item> </item> </tree> Which is inappropriately formatted for my purpose. I would need: <?xml version='1.0' encoding='iso-8859-1'?> <tree id='0'> <item text='1' id='1'> <item text='2' id='2'> <item text='4' id='4'/> </item> <item text='3' id='3'> <item text='5' id='5'> <item text='6' id='6'/> </item> </item> </item> </tree> All nodes with children should end with </item>, leafs without end with />). I included an else-statement, after the foreach, but that obviously only doubles the leafs. else { $leaf = $parent; $indent = str_repeat("\t", $level+1); echo "$indent<item text='$leaf' id='$leaf'/>\n"; } Including further if-statements, left me with a completely screwed xml. Now I run out of ideas how to check for leafs/children and handle them appropriately. Any help ist appreciated!
-
Hey, so to display an image from a database I was using $id = addslashes($_REQUEST['id']); $image = mysql_query("SELECT * FROM store_image WHERE id=$id"); $image = mysql_fetch_assoc($image); $image = $image['image']; header("Content-type: image/jpeg"); echo $image; That worked fine to return an image via matching the id. But I want to get ALL images from the table.. I tried this: $image = mysql_query("SELECT * FROM store_image"); while($image = mysql_fetch_array($image)){ $image = $image['image']; header("Content-type: image/jpeg"); echo $image; } But did not work.. what am I doing wrong?
-
Hi, I am not very good at PHP however I am trying to edit a php function for Magento. $categoryID = $this->getCategoryId(); //the value is like 7,3,6,9 $cats = explode(',', $categoryID); $collection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToSelect('*') ->addAttributeToFilter('category_id', array( array('finset' => '7'), array('finset' => '3'), array('finset' => '6'), array('finset' => '9') ) ); I want to generate the below part automatically based on the value(s) of $cats array('finset' => '7'), array('finset' => '3'), array('finset' => '6'), array('finset' => '9') How can I do it, urgent help will be extremely appreciated. Thanks in advance
-
I have a multidimensional array like so. Array ( [0] => Array ( [0] => Yolo County Sheriff's Home 2008faroo [1] => http://www.yolosheriffs.com/ [2] => 86 ) [1] => Array ( [0] => Fremont, Yolo County, California - Wikipedia, the free encyclopediafaroo [1] => http://en.wikipedia.org/wiki/Fremont,_Yo… [2] => 11 ) [2] => Array ( [0] => The Lonely Island - YOLO (feat. Adam Levine & Kendrick Lamar) - YouTubefaroo [1] => http://www.youtube.com/watch?feature=pla… [2] => 45 ) What i need to do is find duplicate urls in this array, merge them together and combine the score found at [2]. I have scoured the php manual but I can't seem to find a way to merge the duplicate urls and then add the scores to the remaining url. Would it make it any easier to have it in the format Array ( [0] => Array ( [0] => Yolo County Sheriff's Home 2008faroo, array([0] => http://www.yolosheriffs.com/ ,[1] => 0) ) ?? All suggestions appreciated.I have looked at the manual but i don't have the knowledge at this stage to use the array functions in conjunction with foreach loops to achieve what i need.I
- 2 replies
-
- php
- multidimensional arrays
-
(and 3 more)
Tagged with:
-
Notice: Undefined variable: bing_results in /home/msc2012/12254822/public_html/safe_dir/Almost_Gs.php on line 295 Basically, its the 'Interleaving' case that does not work as the echoed variables are not recognized when run on the server but the IDE does not highlight them as errors so it recognizes them. If you pay attention further down the switch statement under other cases I use the same variable $bing_results where it works and is recognized by the server. The scenario is the same with $Blekko and $Google case 'Interleaving': $irl =0; while($irl <= 90) { echo 'hellooo!!'; echo '<a href ='.$bing_results[$irl]['url'].'><h5>'.$bing_results[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$bing_results[$irl]['snippet'].'</p><br>'; echo '<p>'.$bing_results[$irl]['rank'].'<p><br>'; echo '<b>'.$bing_results[$irl]['engine'].'</b><br>'; echo '<hr>'; echo '<a href ='.$Blekko[$irl]['url'].'><h5>'.$Blekko[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$Blekko[$irl]['snippet'].'</p><br>'; echo '<p>'.$Blekko[$irl]['rank'].'<p><br>'; echo '<b>'.$Blekko[$irl]['engine'].'</b><br>'; echo '<hr>'; echo '<a href ='.$google[$irl]['url'].'><h5>'.$google[$irl]['url_title'].'</h5></a><br>'; echo '<p>'.$google[$irl]['snippet'].'</p><br>'; echo '<p>'.$google[$irl]['rank'].'<p><br>'; echo '<b>'.$google[$irl]['engine'].'</b><br>'; echo '<hr>'; $irl++; } break; case 'Non-Aggregated': $nag_c=0; // non aggregated count while ($nag_c <=$blekko_count) { echo '<a href='.$Blekko[$nag_c]['url'].'><h4>'.$Blekko[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$Blekko[$nag_c]['snippet'].'<p>'; echo '<b>'.$Blekko[$nag_c]['engine'].'</b>'; echo '<hr>'; $nag_c++; } $nag_c =0; while ($nag_c <= $google_count) { echo '<a href='.$google[$nag_c]['url'].'><h4>'.$google[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$google[$nag_c]['snippet'].'</p><br>'; echo '<b>'.$google[$nag_c]['engine'].'</b><br>'; echo '<hr>'; $nag_c++; } $nag_c=0; while ($nag_c<=$bing_count) { echo '<a href='.$bing_results[$nag_c]['url'].'>'.'<h4>'.$bing_results[$nag_c]['url_title'].'</h4></a>'; echo '<p>'.$bing_results[$nag_c]['snippet'].'</p>'; echo '<b>'.$bing_results[$nag_c]['engine'].'</b>'; echo '<hr>'; $nag_c++; } case 'Bing': $binger = 0; while ($binger<=$bing_count) { echo '<a href='.$bing_results[$binger]['url'].'>'.'<h4>'.$bing_results[$binger]['url_title'].'</h4></a>'; echo '<p>'.$bing_results[$binger]['snippet'].'</p><br>'; echo '<b>'.$bing_results[$binger]['engine'].'</b><br>'; echo '<hr>'; $binger++; } break; case 'Blekko': $blekr = 0; while ($blekr<=$blekko_count) { echo '<a href='.$Blekko[$blekr]['url'].'><h4>'.$Blekko[$blekr]['url_title'].'</h4></a>'; echo '<p>'.$Blekko[$blekr]['snippet'].'<p>'; echo '<b>'.$Blekko[$blekr]['engine'].'</b>'; echo '<hr>'; $blekr++; } break; case 'Google': $froo = 0; while ($froo <=$google_count) { echo '<a href='.$google[$froo]['url'].'><h4>'.$google[$froo]['url_title'].'</h4></a>'; echo '<p>'.$google[$froo]['snippet'].'</p>'; echo '<b>'.$google[$froo]['engine'].'</b>'; echo '<hr>'; $froo++; } break; } ?>
- 1 reply
-
- unrecognised
- variable
-
(and 2 more)
Tagged with:
-
I am currently using the plugin WP-CommentNavi for comments pagination but whenever a page is clicked it goes to the highest comments page (oldest comments). My comments are purposely displayed newest first and therefore I need the default pagination page to be 1 whenever a link is clicked. I notice there is the same default for other pagination plugins too whereby the highest pagination page (ie if there are 5 pages) page 5 is displayed. At the moment when I load page tellhi####.com/newcastle the page that will be loaded is tellhi####.com/newcastle/comment-page-2/ whereas I want tellhi####.com/newcastle/comment-page-1/ to be loaded I can't be sure this is the relevant code to what I am trying to achieve but I feel the answer might lie in here (below). If not, please tell me and disregard this code. ### Function: Comment Navigation: Boxed Style Paging function wp_commentnavi($before = '', $after = '') { global $wp_query; $comments_per_page = intval(get_query_var('comments_per_page')); $paged = intval(get_query_var('cpage')); $commentnavi_options = get_option('commentnavi_options'); $numcomments = intval($wp_query->comment_count); $max_page = intval($wp_query->max_num_comment_pages); if(empty($paged) || $paged == 0) { $paged = 1; } $pages_to_show = intval($commentnavi_options['num_pages']); $pages_to_show_minus_1 = $pages_to_show-1; $half_page_start = floor($pages_to_show_minus_1/2); $half_page_end = ceil($pages_to_show_minus_1/2); $start_page = $paged - $half_page_start; if($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if(($end_page - $start_page) != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page <= 0) { $start_page = 1; } if($max_page > 1 || intval($commentnavi_options['always_show']) == 1) { $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $commentnavi_options['pages_text']); $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text); echo $before.'<div class="wp-commentnavi">'."\n"; switch(intval($commentnavi_options['style'])) { case 1: if(!empty($pages_text)) { echo '<span class="pages">'.$pages_text.'</span>'; } if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['first_text']); echo '<a href="'.clean_url(get_comments_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>'; if(!empty($commentnavi_options['dotleft_text'])) { echo '<span class="extend">'.$commentnavi_options['dotleft_text'].'</span>'; } } previous_comments_link($commentnavi_options['prev_text']); for($i = $start_page; $i <= $end_page; $i++) { if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<span class="current">'.$current_page_text.'</span>'; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<a href="'.clean_url(get_comments_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>'; } } next_comments_link($commentnavi_options['next_text'], $max_page); if ($end_page < $max_page) { if(!empty($commentnavi_options['dotright_text'])) { echo '<span class="extend">'.$commentnavi_options['dotright_text'].'</span>'; } $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['last_text']); echo '<a href="'.clean_url(get_comments_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>'; } break; case 2; echo '<form action="'.admin_url('admin.php?page='.plugin_basename(__FILE__)).'" method="get">'."\n"; echo '<select size="1" onchange="document.location.href = this.options[this.selectedIndex].value;">'."\n"; for($i = 1; $i <= $max_page; $i++) { $page_num = $i; if($page_num == 1) { $page_num = 0; } if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<option value="'.clean_url(get_comments_pagenum_link($page_num)).'" selected="selected" class="current">'.$current_page_text."</option>\n"; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<option value="'.clean_url(get_comments_pagenum_link($page_num)).'">'.$page_text."</option>\n"; } } echo "</select>\n"; echo "</form>\n"; break; } echo '</div>'.$after."\n"; } } In short I need, anytime a page is clicked, for the comments pagination to be on page 1, not the highest page available. Just so you know I have tried the discussion settings on the wordpress dashboard. Nothing on google either! Failing a full answer, does anyone know the actual php code that determines what pagination page is loaded by default? I received this response via an e-mail but due to my PHP knowledge am unable to implement it, any ideas? ... Just reverse the loop. That'll fix it. Here's the relevant part: http://pastie.org/8166399 You need to go back, i.e. use $i-- Hope I have been clear in my question! Thanks in advance, Paul
- 1 reply
-
- pagination
- loop
-
(and 3 more)
Tagged with:
-
The variable $q_words[$loop_count-1] is shown in the top besides Did you mean? but it fails to come up inside of the hyperlink. Any ideas to why? <?php if ($_POST['query']) { $query = ($_POST['query']); $q_words = explode (" ", $query); $loop_count = 0; $q_count = count(q_words); $s_count = 0; $ss_count = 0; while ($loop_count <= $q_count ) { $query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$q_words[$loop_count].'?key=135a6187-af83-4e85-85c1-1a28db11d5da'; $xml = new SimpleXMLIterator(file_get_contents($query)); foreach ($xml -> suggestion as $suggestion[$s_count]) { $s_count++; } if ($s_count > 1) { echo ('<h4>Did you mean ....? '.$q_words[$loop_count-1].'</h4>'); while ($ss_count <=$s_count) { echo '<a href = "AllinOneMonstaaa.php?query='.$q_words[loop_count-1].' '.$suggestion[$ss_count].'">'.$q_words[loop_count-1].' '.$suggestion[$ss_count].'</a><br>'; $ss_count++; } } $loop_count++; } }
-
I am trying to declare javascript variables from php array values using a loop. Trying to declare javascript var h1 as php array value from $array[1][h], and h2 as $array[2][h], and h3 as $array[3][h],and so on... Here is my code: <SCRIPT LANGUAGE="JavaScript"> for (var i=0;i<61;i++) { var h[i] = "<?php echo $array[i][h] ?>"; var hl[i] = "<?php echo $array[i][hl] ?>"; var hs[i] = "<?php echo $array[i][hs] ?>"; } </script> When I <script type="text/javascript"> document.write(h1); </script> it is blank
-
I've narrowed down my problem to this function... The page won't load, I suspected it was because it was stuck in a loop, but I couldn't see why, checking the error log confirmed this, as there were hundreds of errors for an undeclared variable.... I can't figure out why it is stuck in this loop, and I can't get the undeclared variable to go away, I even renamed it and it is still saying the old name of the variable is undeclared even though it isn't mentioned in the code anywhere I've renamed it.... Can anyone spot what is causing me grief? The only thing that would make sense would be if I wasn't updating the files when I uploaded them, but I am completely certain that I am... error log: code: while ($i<=14) { if($replacement_company_PartNo[$i] = NULL) { //this isn't an item from the database, simply print the description $replacement_Description //write details to new delivery note via 'delnoteitems' $sql = "INSERT INTO `companyorders`.`delnoteitems`(`deliverNote`, `itemDesc`, `itemQuantity`, `itemNotes`, `company_PartNo`) VALUES ('$deliverNote', '$replacement_Part_Name[$i]', '$replacement_Quantity[$i]', '$replacement_Description[$i]', '$replacement_company_PartNo[$i]');" ; $result = mysql_query($sql); if(!$result) {echo "$sql<br>sql error! code: DL4-A031-$i. This isn't an item from the database, skipping write to 'fullnotestock'; however, 'delnoteitems' could not be written to. Round $i."; exit;} } else { //this is an item from the database, the stock listings must be updated as the item is listed onto the delivery note //write details to new delivery note via 'delnoteitems' $sql = "INSERT INTO `companyorders`.`delnoteitems`(`deliverNote`, `itemDesc`, `itemQuantity`, `itemNotes`, `company_PartNo`) VALUES ('$deliverNote', '$replacement_Part_Name[$i]', '$replacement_Quantity[$i]', '$replacement_Description[$i]', '$replacement_company_PartNo[$i]');" ; $result = mysql_query($sql); if(!$result) {echo "$sql<br>sql error! code: DL4-A032-$i. This is an item from the database, havent yet attempted to write to 'fullnotestock'; failed on 'delnoteitems' which could not be written to. Round $i."; exit;} //update the stock listing in 'fullstocklist' $sql = "UPDATE `fullstocklist` SET `Stock`='$stockfromdatabase[$i]' WHERE `company_PartNo`='$replacement_company_PartNo[$i]';" ; $result = mysql_query($sql); if(!$result) {echo "$sql<br>sql error! code: DL4-A033-$i. This is an item from the database, havent yet attempted to write to 'fullnotestock'; failed on 'delnoteitems' which could not be written to. Round $i."; exit;} } $i++; }
- 3 replies
-
- php
- undefined variable
-
(and 2 more)
Tagged with:
-
Hi, I have form that displaying report per week. First thing to do is choose what week then automatically display the date/shift that week ranges. here is my weekly_report.php <?php error_reporting(0); session_start(); ob_start(); date_default_timezone_set("Asia/Singapore"); include('connection.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <title>Weekly Report</title> <head> <link rel="stylesheet" type="text/css" href="op_report.css" /> <script type="text/javascript" src="jquery.js"></script> <script type='text/javascript' src='jquery.autocomplete.js'></script> <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" /> <script type="text/javascript"> //----auto complete week--// $().ready(function() { $("#week_selected").autocomplete("get_week_list.php", { width: 115, matchContains: true, mustMatch: true, selectFirst: false }); $("#week_selected").result(function(event, data, formatted) { $("#week_number").val(data[1]); }); }); /*AJAX*/ function AJAX(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari return xmlHttp; } catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer return xmlHttp; } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp; } catch (e){ alert("Your browser does not support AJAX!"); return false; } } } } //-----get weekdata from week---// function getweekdata() { // if (window.event.keyCode==13 || window.event.keyCode==10) { divid = "week_data"; var url = "get_weekly_data.php"; var str = "id=" + document.getElementById("week_number").value; var xmlHttp = AJAX(); xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){ // document.getElementById(divid).innerHTML=loadingmessage; } if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { var jsonart = xmlHttp.responseText; document.getElementById(divid).innerHTML = jsonart; } } } xmlHttp.open("POST", url, true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", str.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(str); // } } </script> </head> <body onload=document.getElementById("week_selected").focus();> <form name="weekly_report" action="" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="index.php" title="Operator's Shift Report"><span>Operator's Shift Report</span></a></li> <li id="current"> <a href="weekly_report.php" title="Reports"><span>Reports</span></a></li> </ul> </div> <br/> <div> <table> <tr> <td style="border: none;">Type Week:</td> <td><input type="text" name="week_selected" id="week_selected" value="" size="15" onkeyup="getweekdata();"></td> </tr> </table> </div> <input type="hidden" name="week_number" id="week_number"> <div id='week_data'> </div> </form> </body> </html> //get_week_list.php <?php ob_start(); include "connection.php"; $q = strtolower($_GET["q"]); if ($q == '') { header("HTTP/1.0 404 Not Found", true, 404); } //else (!$q) return; else{ $sql = "select week_id, week_number from week_list where week_number LIKE '$q%'"; $rsd = mysql_query($sql); $cnt = mysql_num_rows($rsd); if($cnt > 0) { while($rs = mysql_fetch_array($rsd)) { $pid = $rs['week_id']; $pname = $rs['week_number']; echo "$pname|$pid\n"; } } else { header("HTTP/1.0 404 Not Found", true, 404); } } ?> and here is my get_weekly_data.php // which display the data for that week. <?php ob_start(); include "connection.php"; if($_POST["id"]) { $sql = "select r.report_date, s.shift_type FROM op_reports AS r, shift_list AS s WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY shift_type ORDER BY shift_id ASC"; $res = mysql_query($sql); echo "<table>"; echo "<tr>"; echo "<th>Comp</th>"; while($row = mysql_fetch_assoc($res)) { $report_date = $row['report_date']; $report_shift = $row['shift_type']; echo "<th>$report_date/$report_shift</th>"; } echo "</tr>"; $sql_r = "select r.report_date, s.shift_type FROM op_reports AS r, shift_list AS s WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY shift_type ORDER BY shift_type DESC"; $res_r = mysql_query($sql_r); echo "<tr>"; echo "<th></th>"; while($r = mysql_fetch_assoc($res_r)){ echo "<th>Output</th>"; } echo "</tr>"; $sql_comp = "SELECT DISTINCT p.process_name , r.process_id, r.report_shift FROM op_reports AS r JOIN process_list AS p ON (p.process_id = r.process_id) WHERE WEEK(report_date) + 1 = '" . ($_POST["id"]) . "' GROUP BY process_name ORDER BY p.process_name ASC"; $res_comp = mysql_query($sql_comp); echo "<tr>"; while($row_comp = mysql_fetch_assoc($res_comp)) { $process = $row_comp['process_name']; $process_id = $row_comp['process_id']; echo "<td>$process</td>"; $comp = "SELECT DISTINCT o.compound_type, o.process_id, o.shift_date FROM op_output AS o WHERE process_id = '$process_id' GROUP BY o.shift_id, compound_type ORDER BY compound_type ASC"; $c = mysql_query($comp); echo "<tr>"; while($co = mysql_fetch_assoc($c)) { $compound_type = $co['compound_type']; $process_i = $co['process_id']; $shift_date = $co['shift_date']; echo "<td>$compound_type</td>"; $sql_output = "SELECT DISTINCT o.compound_type, SUM(o.compound_output) AS compound_output, o.process_id, o.shift_id, o.shift_date FROM op_output AS o WHERE process_id = '$process_id' AND o.compound_type = '$compound_type' GROUP BY o.shift_id, o.shift_date, compound_type ORDER BY o.shift_id ASC"; $res_output = mysql_query($sql_output); while($row_output = mysql_fetch_assoc($res_output)) { $compound_output = $row_output['compound_output']; $shift = $row_output['shift_id']; $compound = $row_output['compound_type']; $date = $row_output['shift_date']; if($shift == 1 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 2 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 3 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 4 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } if($shift == 5 && $date == $shift_date) { echo"<td>$compound_output</td>"; } else { echo "<td></td>"; } } echo "</tr>"; } } echo "</tr>"; echo "</table>"; } ?> I attached my sample screenshots that display by this code and also a format that I need to display and the database. My problem now is on displaying of output per date/shift. It's been todays that I tried to fixed this. I hope somebody can help me. Thank you so much sample updated.zip
-
Good day, I have a question using for loop for pagination and setting up the Adjustment. This what I've done. $offs = 0; $numberofrecords = 20; $totalrecords = 490; $totalView = 5; $page = 1; $result = ''; $result .= '<ul class="pagination">'; for ($i=1; $i<=$totalrecords; $i++) { if ($i % $numberofrecords==0) { if($offs == $offset){ $result .= '<li class="active" onclick="paginate('.$offs.')">'.$page.'</li>'; } $result .= '<li onclick="paginate('.$offs.')">'.$page.'</li>'; $offs += $numberofrecords; $page += 1; } } $result .= '</ul>'; The output will be: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 >> My question is how do I set up the adjustment. Adjustment means I am on page 8 and I've got 24 pagination links so the pagination will show something like $offset = 140; << 6 7 8 9 10 .. 20 >> How do I do that using the given loop? I'm sorry I am not really good in looping.
-
Hi all, I need a little help please. I've got some code that creates a socket and a echo server, but I'm not having any luck in getting it to run. I've got the socket created, and closes, but when I try to run the code inside the "Do" "While" section the web page just hangs. I can see the port created on my server. Can some please shed some light at to what I'm doing wrong or what settings I need to change. My server is Apache/2.0.64 (Win32) PHP/5.2.17 .code below. Thanks in anticipation. Nev <?php error_reporting(E_ALL); /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush(); $address = '192.168.0.7'; $port = 10001; if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason:1 " . socket_strerror(socket_last_error()) . "\n"; } if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason:2 $address" . socket_strerror(socket_last_error($sock)) . "\n"; } echo '<p>Hello World</p>'; if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason:3 " . socket_strerror(socket_last_error($sock)) . "\n"; } do { if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason:4 " . socket_strerror(socket_last_error($sock)) . "\n"; break; } /* Send instructions. */ $msg = "\nWelcome to the PHP Test Server. \n" . "To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; socket_write($msgsock, $msg, strlen($msg)); do { if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) { echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n"; break 2; } if (!$buf = trim($buf)) { continue; } if ($buf == 'quit') { break; } if ($buf == 'shutdown') { socket_close($msgsock); break 2; } $talkback = "PHP: You said '$buf'.\n"; socket_write($msgsock, $talkback, strlen($talkback)); echo "$buf\n"; } while (true); socket_close($msgsock); } while (true); socket_close($sock); ?>
-
I'm designing a website for a wine wholesaler that needs to be able to update and display their product catalog in a certain specific way. The site in development is at www.metrocellars.com/new/ Let me first begin by outlining the database tables in use: location​ - a table of 6 records, the broader breakdown of geographic location (Brazil, California, etc.) These rows are used in the navigation menu, and each location has many "regions" referencing them. region​ - the more specific area of origin of each product (wine). Each "Region" references one of the 6 broader "Locations". product​ - The meat of the db, each Product record references a Producer/Winery (PID), a specific Region (RID - which also references a broader Location), and a specific Varietal (VID - Wine type/color). The left part of the image below shows part of the Product table. winery​ - This table holds records of each Winery/Producer referenced by PID in Product table. varietals - This table lists each type of wine, (Pinot, Merlot, etc) referenced by VID in the Product table. ​ On the right side of the above image, I included a visual of the relevant tables with FK relation lines. I haven't figured out which ON DELETE/UPDATE to use, as I got errors a couple times from child rows as I was assigning indexes/keys. I'm a little rusty with the SQL at the moment. Using this model, I need to be able to output the data to a wine list page, but I am having problems putting together the right queries and loops to list the data in the requested format. Here is an example of what the page content should look like when the 'region' California (LID = 2) is clicked on the nav menu. California Slo Down Wines http://www.slodownwines.com/ Broken Dreams Sexual Chocolate Central Coast Jackhammer http://jackhammerwine.com Pinot Noir Happy Canyon of Santa Barbara Cimarone Winery http://www.cimarone.com/ 3CV Bank 3CV Cilla’s Blend Le Clos Secret Gran Premio 3CV Estate Sauvignon Blanc Dragonette Cellars http://dragonettecellars.com/ GMS Rose Sauvignon Blanc Happy Canyon Vineyards http://happycanyonvineyard.com/ Ten Goal Merlot http://happycanyonvineyard.com/ Piocho Margerum Wine Company Sybarite Sauvignon Blanc Paso Robles Spaceman Vineyards Reserve Airspace Santa Barbara County Ampelos Cellars Syrache - Syrah & Grenache Margerum Wine Company http://www.margerumwinecompany.com/ Chenin Blanc M5 Riesling Uber Reserve Tercero http://tercerowines.com/ Grenache Grenache Blanc The Climb Santa Lucia Highlands Jackhammer http://jackhammerwine.com Chardonnay Santa Maria Tyler Winery Bien Nacido Pinot Noir Sta Rita Hills Ampelos Cellars http://ampeloscellars.com/ Pinot Noir Lambda Reserve Rho Reserve Viognier Dragonette Cellars http://dragonettecellars.com/ In the above list, each heading is a record of each "Region" with the same LID as California in the Location table. LID = 2, so I need to list each Region within California, and within each of those listings, list each Wine that has the same RID as that Region, but grouped by their respective Wineries. Basically, there are a few Wineries that have products (child rows I believe) with differing Regions of origin. So, there are products that can have the same PID, but different RID. You can get an idea of the format from the above example. My problem is, is how would I nest the loops and queries, and what joins would be necessary? Any and all help is a godsend. This has been quite a headache.
-
if (is_array($_POST['uid'])) { foreach($_POST['hours']AS $keyd => $value) { echo "UPDATE participantlog SET noshow=1 AND hours=" . $value . " WHERE cid=" . $cid . " AND uid=" . $keyd . "<br>"; mysql_query("UPDATE participantlog SET noshow='1' AND hours='$value' WHERE cid='$cid' AND uid='$keyd'") or die(mysql_error()); } } For some reason my query isn't executing. The foreach is working properly and producing all the right variables (as verified by the echo). But it just isn't updating the DB. Why might this be? Thanks! Clinton
-
I need help displaying more than 12 months on this project. I can't seem to make this loop work without repeating months of the year. All I really need is to display more than 12 months at a time. echo" "; date_default_timezone_set('America/Los_Angeles'); $dateComponents = getdate(); $month = $dateComponents['mon']; $year = $dateComponents['year']; $max = 0; while($max < 12){ if($month == 13){ $month = 1; $year++; } $thisMonth = date("F", mktime(0, 0, 0, $month, 1, 2012)); echo "#$thisMonth$year "; $month++; $max++; } echo " "; ?>
-
Hi, I am building a dashboard/report in work and I have it working at present (not fully) but I made the table structure static, in that if I wanted to make another one for another part of the business, I would need to redo the html table structure. I want to have it create the table itself based on the information in the array. I have included a sample of $data_array and also a screenshot of the current layout I have aswell as a sample of the HTML that is currently in use to generate the below table. I understand its probably going to be a loop job, however Im getting confused as normally you loop for each row, but in this case I need to loop for each TD. If there is any furthe info I can provide that would help, please let me know. Apologies if I have not explained what I am looking for very well. <table border="1" bordercolor="#000000" style="background-color:#FFFFFF" width="100%" cellpadding="3" cellspacing="0"> <tr> <td colspan="3" rowspan="3" class="unused"></td> <td class = "center main_heading" colspan="33">UK Retail</td> </tr> <tr> <td class = "center channel_heading" colspan="<?php echo $chat_width;?>" ><a href="uk_retail_hh.php?c=Chat">Chat</a></td> <td class = "center channel_heading" colspan="<?php echo $phone_width;?>"><a href="uk_retail_hh.php?c=Phone">Phone</a></td> <td class = "center channel_heading" colspan="<?php echo $email_width;?>"><a href="uk_retail_hh.php?c=Email">Email</a></td> </tr> <tr> <td class = "center site_heading chat_ORK" >ORK</td> <td class = "center site_heading chat_EDI" >EDI</td> <td class = "center site_heading chat_VCC" >VCC</td> <td class = "center site_heading chat_HYD" >HYD</td> <td class = "center site_heading chat_BCD" >BCD</td> <td class = "center site_heading chat_SUT" >SUT</td> <td class = "center site_heading" >ORK</td> <td class = "center site_heading" >EDI</td> <td class = "center site_heading" >VCC</td> <td class = "center site_heading" >CBU</td> <td class = "center site_heading" >CPT</td> <td class = "center site_heading" >DAK</td> <td class = "center site_heading" >JAM</td> <td class = "center site_heading" >MNL</td> <td class = "center site_heading" >ORK</td> <td class = "center site_heading" >EDI</td> <td class = "center site_heading" >VCC</td> <td class = "center site_heading" >HYD</td> <td class = "center site_heading" >BCD</td> <td class = "center site_heading" >SUT</td> <td class = "center site_heading" >DAK</td> </tr> <tr> <td colspan="3">Offered</td> <td class = "center Chat_ORK"><?php echo $data_array['Chat']['ORK1']['Incoming'] ?></td> <td class = "center Chat_EDI"><?php echo $data_array['Chat']['EDI3']['Incoming'] ?></td> <td class = "center Chat_VCC"><?php echo $data_array['Chat']['UKVCC']['Incoming'] ?></td> <td class = "center Chat_HYD"><?php echo $data_array['Chat']['HYD']['Incoming'] ?></td> <td class = "center Chat_BCD"><?php echo $data_array['Chat']['BCD']['Incoming'] ?></td> <td class = "center Chat_SUT"><?php echo $data_array['Chat']['SUT']['Incoming'] ?></td> <td class = "center Phone_ORK"><?php echo $data_array['Phone']['ORK1']['Incoming'] ?></td> <td class = "center Phone_EDI"><?php echo $data_array['Phone']['EDI3']['Incoming'] ?></td> <td class = "center Phone_VCC"><?php echo $data_array['Phone']['UKVCC']['Incoming'] ?></td> <td class = "center Phone_CBU"><?php echo $data_array['Phone']['CBU1']['Incoming'] ?></td> <td class = "center Phone_CPT"><?php echo $data_array['Phone']['CPT']['Incoming'] ?></td> <td class = "center Phone_DAK"><?php echo $data_array['Phone']['DAK']['Incoming'] ?></td> <td class = "center Phone_JAM"><?php echo $data_array['Phone']['JAM']['Incoming'] ?></td> <td class = "center Phone_MNL"><?php echo $data_array['Phone']['MNL']['Incoming'] ?></td> <td class = "center Email_ORK"><?php echo $data_array['Email']['ORK1']['Incoming'] ?></td> <td class = "center Email_EDI"><?php echo $data_array['Email']['EDI3']['Incoming'] ?></td> <td class = "center Email_VCC"><?php echo $data_array['Email']['UKVCC']['Incoming'] ?></td> <td class = "center Email_HYD"><?php echo $data_array['Email']['HYD']['Incoming'] ?></td> <td class = "center Email_BCD"><?php echo $data_array['Email']['BCD']['Incoming'] ?></td> <td class = "center Email_SUT"><?php echo $data_array['Email']['SUT']['Incoming'] ?></td> <td class = "center Email_DAK"><?php echo $data_array['Email']['DAK']['Incoming'] ?></td> </tr> <tr> <td colspan="3">Handled</td> <td class = "center Chat_ORK"><?php echo $data_array['Chat']['ORK1']['Handled_incoming'] ?></td> <td class = "center Chat_EDI"><?php echo $data_array['Chat']['EDI3']['Handled_incoming'] ?></td> <td class = "center Chat_VCC"><?php echo $data_array['Chat']['UKVCC']['Handled_incoming'] ?></td> <td class = "center Chat_HYD"><?php echo $data_array['Chat']['HYD']['Handled_incoming'] ?></td> <td class = "center Chat_BCD"><?php echo $data_array['Chat']['BCD']['Handled_incoming'] ?></td> <td class = "center Chat_SUT"><?php echo $data_array['Chat']['SUT']['Handled_incoming'] ?></td> <td class = "center Phone_ORK"><?php echo $data_array['Phone']['ORK1']['Handled_incoming'] ?></td> <td class = "center Phone_EDI"><?php echo $data_array['Phone']['EDI3']['Handled_incoming'] ?></td> <td class = "center Phone_VCC"><?php echo $data_array['Phone']['UKVCC']['Handled_incoming'] ?></td> <td class = "center Phone_CBU"><?php echo $data_array['Phone']['CBU1']['Handled_incoming'] ?></td> <td class = "center Phone_CPT"><?php echo $data_array['Phone']['CPT']['Handled_incoming'] ?></td> <td class = "center Phone_DAK"><?php echo $data_array['Phone']['DAK']['Handled_incoming'] ?></td> <td class = "center Phone_JAM"><?php echo $data_array['Phone']['JAM']['Handled_incoming'] ?></td> <td class = "center Phone_MNL"><?php echo $data_array['Phone']['MNL']['Handled_incoming'] ?></td> <td class = "center Email_ORK"><?php echo $data_array['Email']['ORK1']['Handled_incoming'] ?></td> <td class = "center Email_EDI"><?php echo $data_array['Email']['EDI3']['Handled_incoming'] ?></td> <td class = "center Email_VCC"><?php echo $data_array['Email']['UKVCC']['Handled_incoming'] ?></td> <td class = "center Email_HYD"><?php echo $data_array['Email']['HYD']['Handled_incoming'] ?></td> <td class = "center Email_BCD"><?php echo $data_array['Email']['BCD']['Handled_incoming'] ?></td> <td class = "center Email_SUT"><?php echo $data_array['Email']['SUT']['Handled_incoming'] ?></td> <td class = "center Email_DAK"><?php echo $data_array['Email']['DAK']['Handled_incoming'] ?></td> </tr> Array ( [Phone] => Array ( [CBU1] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => CBU1 [phone_skill] => Primary [OU] => UK [Incoming] => 1005 [Handled_incoming] => 902 [Aband_6] => 39 [Aband_210] => 39 [Aband_30] => 32 [Ans_60sec] => 810 [Ans_210sec] => 966 [Ans_30sec] => 683 [SL_60] => 0.8448 [SL_210] => 1.0000 [SL_30] => 0.7114 ) [DAK] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => DAK [phone_skill] => Primary [OU] => UK [Incoming] => 913 [Handled_incoming] => 876 [Aband_6] => 18 [Aband_210] => 18 [Aband_30] => 14 [Ans_60sec] => 807 [Ans_210sec] => 894 [Ans_30sec] => 730 [SL_60] => 0.9036 [SL_210] => 0.9989 [SL_30] => 0.8149 ) [JAM] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => JAM [phone_skill] => Primary [OU] => UK [Incoming] => 1171 [Handled_incoming] => 1377 [Aband_6] => 15 [Aband_210] => 15 [Aband_30] => 12 [Ans_60sec] => 1147 [Ans_210sec] => 1155 [Ans_30sec] => 1123 [SL_60] => 0.9923 [SL_210] => 0.9991 [SL_30] => 0.9693 ) [MNL] => Array ( [statistic_date] => 2013-05-20 [time] => 530 [site] => MNL [phone_skill] => Primary [OU] => UK [Incoming] => 1918 [Handled_incoming] => 1764 [Aband_6] => 24 [Aband_210] => 27 [Aband_30] => 16 [Ans_60sec] => 1711 [Ans_210sec] => 1891 [Ans_30sec] => 1459 [SL_60] => 0.9046 [SL_210] => 1.0000 [SL_30] => 0.7690 ) [ORK1] => Array ( [statistic_date] => 2013-05-20 [time] => 700 [site] => ORK1 [phone_skill] => Primary [OU] => UK [Incoming] => 133 [Handled_incoming] => 128 [Aband_6] => 3 [Aband_210] => 3 [Aband_30] => 2 [Ans_60sec] => 96 [Ans_210sec] => 130 [Ans_30sec] => 86 [SL_60] => 0.7444 [SL_210] => 1.0000 [SL_30] => 0.6617 ) [UKVCC] => Array ( [statistic_date] => 2013-05-20 [time] => 700 [site] => UKVCC [phone_skill] => CsPromotions [OU] => UK [Incoming] => 1264 [Handled_incoming] => 1191 [Aband_6] => 28 [Aband_210] => 30 [Aband_30] => 27 [Ans_60sec] => 1133 [Ans_210sec] => 1234 [Ans_30sec] => 1047 [SL_60] => 0.9185 [SL_210] => 1.0000 [SL_30] => 0.8497 ) [CPT] => Array ( [statistic_date] => 2013-05-20 [time] => 800 [site] => CPT [phone_skill] => Primary [OU] => UK [Incoming] => 624 [Handled_incoming] => 624 [Aband_6] => 16 [Aband_210] => 16 [Aband_30] => 13 [Ans_60sec] => 562 [Ans_210sec] => 608 [Ans_30sec] => 535 [SL_60] => 0.9263 [SL_210] => 1.0000 [SL_30] => 0.8782 ) [EDI3] => Array ( [statistic_date] => 2013-05-20 [time] => 900 [site] => EDI3 [phone_skill] => Primary [OU] => UK [Incoming] => 779 [Handled_incoming] => 775 [Aband_6] => 21 [Aband_210] => 22 [Aband_30] => 19 [Ans_60sec] => 724 [Ans_210sec] => 757 [Ans_30sec] => 708 [SL_60] => 0.9564 [SL_210] => 1.0000 [SL_30] => 0.9332 ) ) [Chat] => Array ( [BCD] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => BCD [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 809 [Handled_incoming] => 777 [Aband_6] => 10 [Aband_210] => 11 [Aband_30] => 8 [Ans_60sec] => 765 [Ans_210sec] => 798 [Ans_30sec] => 687 [SL_60] => 0.9580 [SL_210] => 1.0000 [SL_30] => 0.8591 ) [HYD] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => HYD [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 862 [Handled_incoming] => 954 [Aband_6] => 8 [Aband_210] => 10 [Aband_30] => 8 [Ans_60sec] => 818 [Ans_210sec] => 852 [Ans_30sec] => 765 [SL_60] => 0.9582 [SL_210] => 1.0000 [SL_30] => 0.8968 ) [ORK1] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => ORK1 [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 314 [Handled_incoming] => 317 [Aband_6] => 3 [Aband_210] => 3 [Aband_30] => 3 [Ans_60sec] => 311 [Ans_210sec] => 311 [Ans_30sec] => 290 [SL_60] => 1.0000 [SL_210] => 1.0000 [SL_30] => 0.9331 ) [SUT] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => SUT [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 1369 [Handled_incoming] => 1234 [Aband_6] => 21 [Aband_210] => 22 [Aband_30] => 19 [Ans_60sec] => 1299 [Ans_210sec] => 1347 [Ans_30sec] => 1181 [SL_60] => 0.9642 [SL_210] => 1.0000 [SL_30] => 0.8766 ) [UKVCC] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => UKVCC [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 300 [Handled_incoming] => 300 [Aband_6] => 2 [Aband_210] => 2 [Aband_30] => 2 [Ans_60sec] => 298 [Ans_210sec] => 298 [Ans_30sec] => 263 [SL_60] => 1.0000 [SL_210] => 1.0000 [SL_30] => 0.8833 ) [EDI3] => Array ( [statistic_date] => 2013-05-20 [time] => 900 [site] => EDI3 [phone_skill] => PrimaryChat [OU] => UK [Incoming] => 273 [Handled_incoming] => 296 [Aband_6] => 2 [Aband_210] => 2 [Aband_30] => 2 [Ans_60sec] => 269 [Ans_210sec] => 271 [Ans_30sec] => 251 [SL_60] => 0.9927 [SL_210] => 1.0000 [SL_30] => 0.9267 ) ) [Email] => Array ( [BCD] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => BCD [phone_skill] => RetailEmail [OU] => UK [Incoming] => 1309 [Handled_incoming] => 1293 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [CPT] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => CPT [phone_skill] => CsPromotionsEmail [OU] => UK [Incoming] => 15 [Handled_incoming] => 49 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [DAK] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => DAK [phone_skill] => Email [OU] => UK [Incoming] => 1081 [Handled_incoming] => 1129 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [EDI3] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => EDI3 [phone_skill] => Email [OU] => UK [Incoming] => 709 [Handled_incoming] => 754 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [HYD] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => HYD [phone_skill] => RetailEmail [OU] => UK [Incoming] => 2012 [Handled_incoming] => 1766 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [ORK1] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => ORK1 [phone_skill] => Email [OU] => UK [Incoming] => 1320 [Handled_incoming] => 336 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [SUT] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => SUT [phone_skill] => CarriersEmail [OU] => UK [Incoming] => 3785 [Handled_incoming] => 3704 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) [UKVCC] => Array ( [statistic_date] => 2013-05-20 [time] => 0 [site] => UKVCC [phone_skill] => CarriersEmail [OU] => UK [Incoming] => 746 [Handled_incoming] => 750 [Aband_6] => 0 [Aband_210] => 0 [Aband_30] => 0 [Ans_60sec] => 0 [Ans_210sec] => 0 [Ans_30sec] => 0 [SL_60] => 0.0000 [SL_210] => 0.0000 [SL_30] => 0.0000 ) ) )
-
I have a set rental amount with some variable making an equation. The final variable is the TOTAL of all the equations, i need the total of this variable <?php //option 1 52 weeks $weeklyToStudent = $row_rsTenProp['rental_price']; $fourWeeksSecurityDep = 4 * $weeklyToStudent; $fivetwoWeeksPayable = $weeklyToStudent * 52; $fee = 184.80; $resFee = 250; $fivetwoPayIncFeedSecDep = $fourWeeksSecurityDep + $fivetwoWeeksPayable + $fee; $initPay15Wks = $weeklyToStudent*15; $initPay15WksFeeSecDep = $initPay15Wks + $fee + $fourWeeksSecurityDep; $balanceB4MovingIn = $initPay15WksFeeSecDep - $resFee; $second14Wks = $weeklyToStudent * 14; $third14Wks = $weeklyToStudent * 14; $fourth9Wks = $weeklyToStudent * 9; $totalPayment = $initPay15WksFeeSecDep + $second14Wks + $third14Wks + $fourth9Wks; ?> <?php do { ?> <tr> <td class="table-text"><a href="customer-info.php?recordID=<?php echo $row_rsTenProp['userid']; ?>"><?php echo $row_rsTenProp['userid']; ?></a></td> <td class="table-text"><?php echo $row_rsTenProp['weeks'] / 7; ?> weeks</td> <td class="table-text"><?php echo $row_rsTenProp['payment_option']; ?></td> <td class="table-text"><?php echo $row_rsTenProp['rental_price']; ?></td> <td class="table-text"><?php echo $row_rsTenProp['prop_id']; ?></td> <td class="table-text"><?php echo DoFormatCurrency($totalPayment, 2, ',', '.', '£ '); ?></td> <td> </td> <td> </td> </tr> <?php } while ($row_rsTenProp = mysql_fetch_assoc($rsTenProp)); ?> i need to multiple the $totalPayment to get the TOTAL of this variable <?php $totalPaymentTot = 0; while ($totalPayment = ($row_totalPayment)); $totalPaymentTot += $row_totalPayment;{ $row_totalPayment; } echo $totalPaymentTot;?>
-
Hi. I'm having a problem regarding my codes involving radio buttons and subloop. I couldn't retrieve the data from post and I can't insert them to the database. I just couldn't find the error. Here's my form's code: <form method="post"> <?php $select_paragraph=mysql_query('SELECT * FROM dependency'); $questrows = 0; while($get_paragraph = mysql_fetch_array($select_paragraph)) { $TestID = $get_paragraph['testId']; $Dependid = $get_paragraph['DependencyId']; echo" <table border='1'> <tr class='classheader1'> <td align='center' class='paragraph'>". $get_paragraph['Situation']. "</td> <table>"; $select_question=mysql_query('SELECT * FROM dependentitems where DependencyId="'.$Dependid.'"'); while($get_question = mysql_fetch_array($select_question)) { echo $LitId = $get_question['LiteralId']; echo $ItemID = $get_question['ItemId']; echo" <tr><td align='left' class='paragraph'><br>". $get_question['Question']. "</td></tr> <tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option1']. "'>". $get_question['Option1']. "</td></tr> <tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option2']. "'>". $get_question['Option2']. "</td></tr> <tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option3']. "'>". $get_question['Option3']. "</td></tr> <tr><td align='left' class='paragraph'><input type='radio' name='Option".$questrows."' value = '". $get_question['Option4']. "'>". $get_question['Option4']. "</td></tr> "; echo "Radio Names = Option".$questrows." "; $questrows++; } echo" </table> </td> </tr> </table> "; } ?> <input type="submit" name="enter" value="Submit"/> </form> And here's the code where I retrieve the post so I could insert them into my database: <?php if(@$_POST['enter']) { $select_paragraph=mysql_query('SELECT * FROM dependency'); $questrows = 0; while($get_paragraph = mysql_fetch_array($select_paragraph)) { $TestID = $get_paragraph['testId']; $Dependid = $get_paragraph['DependencyId']; $select_question=mysql_query('SELECT * FROM dependentitems where DependencyId="'.$Dependid.'"'); while($get_question = mysql_fetch_array($select_question)) { echo "Hi".@$option=$_POST['Option'.$questrows]; echo "<br>LitId = ".$LitId = $get_question['LiteralId']; echo "<br>ItemId = ".$ItemID = $get_question['ItemId']; echo '<br>ThisOption'.$questrows; $insertToTemp="insert into temp(StudId, TestId, ItemId, LiteralId, Choice) values(1, 3, $ItemID,$LitId,'$option[$questrows]')"; mysql_query($insertToTemp); $questrows++; echo "<br>"; } } } ?> Hope you could help me find the error. Thanks.
-
I've got a foreach ($acct as $val){ $acc_s = explode(',',$val["access_type"]); } The value of ACC will Array from every foreach var_dump($acc_s); Output: array(1) { [0]=> string(1) "1" } array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } array(2) { [0]=> string(1) "3" [1]=> string(1) "4" } array(1) { [0]=> string(1) "3" } My question is, how do I make a condition if the value of the "explode" element have 1 or 2 or 3 or 4. I'd try. for($i=0;$i<count($acc_s);$i++){ $out_acc = $acc_s[$i]; } But it won't give me the right output to what I need.
-
I have an array ($sm[]) which stores several decimal numbers. Now I want to insert these data present in the array to a column "SM" present under empty table "sm". So anybody please suggest how should I do this by writing few lines of php code.
-
Hello all! I want to format my post array so that I can insert the data into the database in a particular way such as this: Also, I'm making this dynamic in that I'm not always going to know the column names. So hardcoding the keys is not an option for this solution. INSERT INTO invoice_items (itemCode, itemDesc, itemQty, itemPrice, itemLineTotal) VALUES (1000', Widget0', 10', '25.00', '900.54), (1001', Widget1', 11', '25.01', '900.54), (1002', Widget2', 12', '25.02', '900.54) BUT my current output looks like this. Which is not right of course: INSERT INTO invoice_items (itemCode, itemDesc, itemQty, itemPrice, itemLineTotal) VALUES (1000', '1001', '1003), (Widget', 'Red Hat', 'ioPad with Cover), (1', '2', '3), (100.5', '25.02', '300.18), (25.02', '600.36', '900.54); I don't think I'm that far from having a solution but I can't wrap my head around how to get the output the way I need it. The original $_POST Array: Array ( [itemCode] => Array ( [0] => 1000 [1] => 1001 [2] => 1003 ) [itemDesc] => Array ( [0] => Widget [1] => Red Hat [2] => ioPad with Cover ) [itemQty] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [itemPrice] => Array ( [0] => 100.5 [1] => 25.02 [2] => 300.18 ) [itemLineTotal] => Array ( [0] => 100.50 [1] => 50.04 [2] => 900.54 ) ) Here's the loop that creates the following arrays: $fields = $values = array(); foreach ($post as $column => $value) { $fields[] = $column; $value = implode("', '", $value); $values[$column] = $value; } $columns Array: Array ( [0] => itemCode [1] => itemDesc [2] => itemQty [3] => itemPrice [4] => itemLineTotal ) $values Array: Array ( [itemCode] => 1000', '1001', '1003 [itemDesc] => Widget', 'Red Hat', 'ioPad with Cover [itemQty] => 1', '2', '3 [itemPrice] => 100.5', '25.02', '300.18 [itemLineTotal] => 25.02', '600.36', '900.54 ) Create the sql statement: $query = "INSERT INTO " . $this->table ; $query .= " (" . implode(", ", $fields) . ") "; $query .= "VALUES (" . implode("), (", $values) . "); "; Which outputs this: INSERT INTO invoice_items (itemCode, itemDesc, itemQty, itemPrice, itemLineTotal) VALUES (1000', '1001', '1003), (Widget', 'Red Hat', 'ioPad with Cover), (1', '2', '3), (100.5', '25.02', '300.18), (25.02', '600.36', '900.54); THANK YOU for any help you can provide me!
-
I've been given a function that return all the list of data in an array. Only that function I can update nothing else specially on the database. From all the list of data, by using foreach I can print all the list of data. But my problem now is on the list of data e.g. (name, address, phone_number, zip_code). . How can I make a condition that will only show all the data by the same zip_code or name whatever. e.g. (John, John, John, John) for me it will be easy if i have access on the database, but unfortunately I don't have. Anyone can help me with this?
-
is it possible to combine css with php while loop and table
et4891 posted a topic in PHP Coding Help
I'm wondering if it's possible in an easy way that when I use while function to call out a bunch of data and put them into table but I want to use css to make it one row with regular background and one row with light background. hopefully what I sad make sense.... this is what I have echo "<style type='text/css'>"; echo "th {background: #CEED5E;}"; echo "</style>"; echo "<table border=1>"; echo "<tr><th>Product ID</th><th>Title</th><th>Author</th><th>Description</th></tr>"; while ($row = mysqli_fetch_assoc($result)) { echo "<tr><td>" . $row["id"] . "</td><td>" . $row["title"] . "</td><td>" . ucwords(strtolower($row["authorFirstName"] . " " . $row["authorLastName"])) . "</td><td>" . $row["description"] . "</td></tr>"; } echo "</table>"; -
I have created a user defined function to return a string value function getModel($part) { $root = substr($part,0,4); $query = "SELECT Root, Model FROM tbl_Root WHERE Root = '$root'"; $result = mysql_query($query) or die ("Query Root failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { if (in_array($root, $rec)): $Model = $rec['Model']; else: $Model = 'UNKNOWN'; endif; } return $Model; } When trying to find the attributes of several hundred part numbers, I pass them to a MySQL temp table that would then select the distinct part numbers and loop them through my functions. $query = "SELECT DISTINCT A FROM TempAttributes"; $result = mysql_query($query) or die ("Query failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { $part = mysql_escape_string($rec['A']); $Model = getModel($part); $query = "REPLACE INTO tbl_Attributes (Part, Model) VALUES ('$part', '$Model')"; $endresult = mysql_query($query) or die ("Query Load failed: " . mysql_error()); } The line of code that stops the execution of my loop is $Model = getModel($part); I executed the loop with this line of code in and it stops after the first part number. When I comment this line of code out, my loop processes all of my part numbers, but of course not with the return values I am looking for. Why does my user defined function not process through the while loop to assign the $Model variable the return value of the getModel function? Please help!
-
Hi, I need help with looping through the dates of working days (Monday to Friday) for the following week. I need to send an email once a week (probably on a Thursday or Friday) informing people of their rooms for the following week. I need to loop through each day, starting with Monday and finishing on Friday. I wrote this: for($i=0;$i<5;$i++) { echo date('Y-m-j', strtotime('Monday+'.$i)).'<br />'; } I thought this would work, but it returns the correct date for next Monday (2013-03-25) and then the other 4 days are all showing as 2013-03-24. Any ideas how I can get this to work? Thank you for taking the time to help. Many Thanks, John