PHP - Foreach Printing In Html Table
I want to print in an html table the Seasons,the Months,and the days of each month.
the following code prints the seasons and the days i need another foreach in between that prints the months also Any ideas??? Please help... $seasons=array ( "Fall"=> array ("September"=>"30","October"=>"31","November"=>"30"), "Winter"=> array ("December"=>"31","January"=>"31","February"=>"28"), "Spring"=> array ("March"=>"31","April"=>"30","May"=>"31"), "Summer"=> array ("June"=>"30","July"=>"31","August"=>"31") ); $tab = "<table border=\"1\">"; foreach($seasons as $season => $months) { $tab .= "<tr><td colspan=\"4\">$season</td></tr>" ; $tab .= "<tr>" ; foreach($seasons[$season] as $days) { $tab .= "<td>$days</td>" ; } $tab .= "</tr>" ; } $tab .= "</table>" ; echo $tab ; Similar TutorialsHello everyone,
i'm Osiris and i'm stuck with this PHP/HTML code, i'm fairly new at this so this might be a dumb question.
i have a database, but i want to output all data into a table from the database using HTML codes.
i had it so far that i could outpust the info in just plain text but it doesn't output in the HTML table.
Can anyone see what i did wrong?
This is my PHP code its in the body section
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`'; mysql_select_db('mtgstock'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo '<table class=mytable>'; echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>"; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr><td>"; echo $row['Name'] echo "</td><td>"; echo $row['Color']; echo "</td><td>"; echo $row['Type']; echo "</td><td>"; echo $row['Subtype']; echo "</td><td>"; echo $row['Power']; echo "</td><td>"; echo $row['Toughness']; echo "</td><td>"; echo $row['Manacost']; echo "</td><td>"; echo $row['Rarity']; echo "</td><td>"; echo $row['Expansion']; echo "</td><td>"; echo $row['Foil']; echo "</td><td>"; echo $row['Stock']; echo "</td></tr>"; } echo "</table>"; mysql_close($conn); ?>Thanks in advance! I've got a database file from sqlite, there is a multidimensional array in it with 10 metals. I just want two print out each element in a table It won't get all the separate data inside a HEREDOC foreach ($product_prices as $metal => $prices) "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][28]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][36]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][45]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][100]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][10]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][1]*$l_conv*$w_conv,4). "</td></tr>"; The following generic code prints out a given table in my database, by first getting the fieldnames and putting them as the title of each column, and then getting the values. How do I change it so that if the name of the field is "password", the value will echo "----" instead of the password? $sql = "SELECT * FROM $tablename"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $row = 1; ?> <table width="90%" border="1"><?php //the MYSQL_ASSOC gets field names instead of numbers while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { ?><tr><?php foreach ($line as $col_key => $col_value) { ?><th><?php echo $col_key;?></th><?php } ?></tr><?php } ?><tr><?php foreach ($line as $col_value) { ?><td><?php echo $col_value;?></td><?php } ?></tr><?php $row++; Hi All Please see code below. I cannot get my table to produce correctly. I have a multidimensional array $data['id']['fieldid']=$row['content'] I want this to loop through and create a new line in a table for each sub-array. hence the table would look like this. (id1 in this row) field1 content field2 content field3 content field4 content (id2 in this row) field1 content field2 content field3 content field4 content (id3 in this row) field1 content field2 content field3 content field4 content (id4in this row) field1 content field2 content field3 content field4 content etc etc. The table can grow or shrink depending on the data I'm retrieving. <table><font size="8"> <tr> <?php foreach ($header_out as $value){ echo "<td>$value</td>"; } ?> </tr> <?php echo"<tr>"; foreach($data as $value){ $count++; foreach($value as $dataout){ echo "<td>$dataout $count</td>"; } }echo"</tr><tr>"; ?> </tr></font></table> <?php } ?> The header section works fine, but the double foreach loop seems to be where I'm failing. Any advice guys? Hi all, I'm trying to set up a situation where a function loops through a multidimensional array and echos an html block for each item in the $skus['skunum'] array and also increments $i each time . ( Each is a product on the site) The catch is that I'm trying to have a function within that one that goes through the $skus['sizes'] and echoes an option if the substring (shirt size) exists. The idea being that I can manage products by adding 4 elements, Skunum, name, price and size. And well, I'm failing miserably. At this point it won't even work because of the variable scope, I'm getting Notice: Undefined variable: skus from the functions, but am not sure of the right way to get that information. Am I going about doing this entirely wrong or am I on the right track? Code: [Select] <?php $BANDNAME="Apocalypse"; $BANDCAPS="APOCALYPSE"; $BANDLOWER="apocalypse"; $SKUCAPS="FGD"; $skus = array ( "skunum"=>array ( "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112" ), "name"=>array ( "RIDDICK /TSHIRT", "MAFIA / TSHIRT", "ORACLES / TSHIRT", "AGONY / TSHIRT", "BLOODY VIOLINIST / TSHIRT", "THE VIOLATION / TSHIRT", "AGONY-TOUR DATES / TSHIRT", "BAND PHOTO / TSHIRT", "SILVER AGONY LOGO / TSHIRT", "PHOENIX-TOUR DATES / TSHIRT", "PHOENIX / TSHIRT", "BLOODY VIOLINIST / ZIP HOOD" ), "price"=>array ( "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "15.95", "42.95" ), "sizes"=>array ( "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X", "S, M, L, 1X, 2X, 3X, 4X" ) ); function makeProducts() { //Products Sizes $sizes = $skus['sizes'][$i]; $S="S";$M="M";$L="L";$XL="1";$XXL="2";$XXXL="3";$XXXXL="4"; $small = strpos($sizes,$S); $medium = strpos($sizes,$M); $large = strpos($sizes,$L); $xlarge = strpos($sizes,$XL); $xxlarge = strpos($sizes,$XXL); $xxxlarge = strpos($sizes,$XXXL); $xxxxlarge = strpos($sizes,$XXXXL); function sizeOptions () { if($small === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'S">S</OPTION>'; } if($medium === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'M">M</OPTION>'; } if($large === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'L">L</OPTION>'; } if($xlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'X">XL</OPTION>'; } if($xxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XX">XXL</OPTION>'; } if($xxxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XXX">XXXL</OPTION>'; } if($xxxxxlarge === true) { echo '<OPTION value="'.$SKUCAPS.$skus['skunum'][$i].'XXXX">XXXXL</OPTION>'; } } foreach ( $skus['skunum'] as $value){ echo '<!-- PRODUCT BEGIN --> <li class="product" > <a href="product_files/large/'.$SKUCAPS.$skus['skunum'][$i].'jpg" rel="lightbox"><img src="product_files/'.$SKUCAPS.$skus['skunum'][$i].'.png"></a><br> <strong>'.$skus['name'][$i].'</strong><br>('.$SKUCAPS.$skus['skunum'][$i].')<br>$'.$skus['price'][$i].'<br> <form name="'.$SKUCAPS.$skus['skunum'][$i].'" method="GET" target="_blank" action="http://www.jsrdirect.com/cgi-bin/Make-a-Store.cgi"> <input type="hidden" name="band" value="'.$BANDCAPS.'"> <input type="hidden" name="back" value="http://www.jsrdirect.com/bands/'.$BANDLOWER.'/index.html"> <strong>Qty:</strong> <input type="text" name="quantity" size="1" value="1" > <strong>Size:</strong> <SELECT name="item">' .sizeOptions(); '</SELECT> <br><br> <input type="image" src="images/addtocart.png" value="Add To Cart"> </form> </li> <!-- Product End -->'; } } // End Function ?> I have some code that will update a record and is generic, meaning any POST variables can be used - whatever you have on the form. See below: Code: [Select] $set = array(); foreach($_POST as $field => $value){ $field = mysql_real_escape_string($field); $value = mysql_real_escape_string($value); $set[] = "`{$field}` = '{$value}'"; } $query .= implode(", ",$set) . " WHERE $id_name = '".$id."' LIMIT 1"; mysql_query($query) or die(mysql_error()); My question is, how would I modify this to insert a NEW record (not update an existing one). I'm not sure how to order this within a foreach statement because the add query has a different form: insert into tabel (all the fieldnames here) VALUES (all the values here) Hello everyone !
I am currently developing a module for my site that will allow me to classify each solution to help a disability by type. Type : Visual disability Solution : Add screen readers For this, I have a database in which these types and solutions are found. In this database, the solutions of one type or another are not in a defined order. They can be put randomly, when a user adds one. I need to display, in a table, these Types first (as a title), then the solutions corresponding to this type. I manage to generate a display thanks to a foreach loop, but my solutions are all mixed up and therefore not clearly sorted.
Visual disability Audio-described cut-scenes Highlighted path to follow Sensitivity settings for all the controls Screen readers on menus Slow down the game speed But I would need it to look like this: Visual disability Audio-described cut-scenes Highlighted path to follow Screen readers on menus Slow down the game speed Physical disability Sensitivity settings for all the controls In my example above, only the solution "Sensitivity settings for all the controls" is part of the "Physical disability" type. The rest is part of the "Visual disability" type. Here is the code I currently use to retrieve my information from my database and display it. It's a Wordpress.
/*====== Accessibility Options ======*/ function cloux_accessibility_options() { if ( function_exists( 'rwmb_meta' ) ) { $output = ""; $accessibility_options = rwmb_meta( 'accessibility-options' ); $accessibility_options_status = rwmb_meta( 'accessibility-options-status' ); if( $accessibility_options_status == "1" ) { if( !empty( $accessibility_options ) ) { $output .= '<div class="accessibility-options widget-box">'; $output .= cloux_title( $title = esc_html__( 'Accessibility Options', 'cloux' ), $style = "style-4", $align = "left", $colored_title = '' ); $output .= '<ul>'; $output .= '<li class="title visual_disability">' . esc_html__( 'Visual disability', 'cloux' ) . '</li>'; $output .= '</ul>'; foreach ( $accessibility_options as $accessibility_options ) { if( !empty( $accessibility_options ) ) { $accessibility_name = isset( $accessibility_options['accessibility-options-name'] ) ? $accessibility_options['accessibility-options-name'] : ''; $accessibility_type = isset( $accessibility_options['accessibility-type-name'] ) ? $accessibility_options['accessibility-type-name'] : ''; $accessibility_type = get_term( $accessibility_type, 'accessibility' ); $accessibility_type_name = $accessibility_type->name; $availability = isset( $accessibility_options['availability'] ) ? $accessibility_options['availability'] : ''; if ( $accessibility_type_name == "Visual disability" ){ if( !empty( $accessibility_name ) or !empty( $availability )) { $output .= '<ul>'; $output .= '<li class="item accessibility_name">'; if( !empty( $accessibility_name ) ) { $accessibility_name = get_term( $accessibility_name, 'accessibility' ); if( ( !empty( $accessibility_name ) ) ) { $output .= '<a href="' . get_term_link( $accessibility_name ) . '">' . esc_attr( $accessibility_name->name ) . '</a>'; } } $output .= '</li>'; $output .= '<li class="item visual_disability status">'; if( $availability == "1" ) { $output .= '<i class="fas fa-check" aria-hidden="true"></i>'; } else { $output .= '<i class="fas fa-times" aria-hidden="true"></i>'; } $output .= '</li>'; } } if ( $accessibility_type_name == "Motor/Physical disability" ){ if( !empty( $accessibility_name ) or !empty( $availability )) { $output .= '<ul>'; $output .= '<li class="item accessibility_name">'; if( !empty( $accessibility_name ) ) { $accessibility_name = get_term( $accessibility_name, 'accessibility' ); if( ( !empty( $accessibility_name ) ) ) { $output .= '<a href="' . get_term_link( $accessibility_name ) . '">' . esc_attr( $accessibility_name->name ) . '</a>'; } } $output .= '</li>'; $output .= '<li class="item visual_disability status">'; if( $availability == "1" ) { $output .= '<i class="fas fa-check" aria-hidden="true"></i>'; } else { $output .= '<i class="fas fa-times" aria-hidden="true"></i>'; } $output .= '</li>'; } } $output .= '</ul>'; } } $output .= '</div>'; } } return $output; } } Thank you in advance for all the help you can give me! Edited January 13 by Sagaroth I have 64 rows of players and want each User to be able to choose to bookmark an player, as well as unbookmark it too. I have a bookmark table set up, and each time a User decides to bookmark(+) or unbookmark(-) an player a row is created in the data table. (Matching the player ID and User ID) That's working fine. A query reads the most recent row for each player to determine if there is a + or - button next to each player. Testing the query and adding some dummy data, that part of it works too. However, the issue is the initial state, which I want to be a +. Once I go live, the table will be empty, nothing for the query to return/produce. How do I create an initial state of a + with no rows and have it not used or swapped out when Users start clicking + or -?
$query = "SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1 "; $results = mysqli_query($con,$query); echo mysqli_error($con); while($row = mysqli_fetch_assoc($results)) { echo $row['bookmark']; if($row['bookmark'] == 0) { echo '-'; // this is where a form goes to remove a bookmark } else { echo '+'; // this is where a form goes to add a bookmark } } I tried to get it with CASE, but I don't think that's the right path. I also looked at UNION. I was able to get it to produce an initial state of +, but it still printed the already made up sample data too (so I have three instances of ++ or +-). (Players 2, 4 and 4)
Here is the what the UNION query looked like: $query = "(SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1) UNION (SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."' ORDER BY p.id desc LIMIT 1) ";
Dear Friends, I am alot before doing the mixed content of php and HTML in single variable in PHP.. I could not get the data even though there is not SYNTAX error.. please look my code and advise
$htmlcontent .=" <tr> <td colspan=\"8\">".$details."></td> </tr>"; for($k=0;$k<count($reg_years[$details]);$k++) { $year = (int)($reg_years[$details][$k]); $singlecount[$year] = array_filter($result[$details],function($details1) use ($year){ return ($details1['reg_year'] == $year && $details1['bench_type'] == 1); }); $divisioncount[$year] = array_filter($result[$details],function($details2) use ($year){ return ($details2['reg_year'] == $year && $details2['bench_type'] == 2); }); $fullcount[$year] = array_filter($result[$details],function($details3) use ($year){ return ($details3['reg_year'] == $year && $details3['bench_type'] >= 3); }); $rpcount[$year] = array_filter($result[$details],function($rp) use ($year){ return ($rp['reg_year'] == $year && $rp['bench_type'] == 'RP'); }); $mjccount[$year] = array_filter($result[$details],function($mjc) use ($year){ return ($mjc['reg_year'] == $year && $mjc['bench_type'] == 'MJC'); }); $cocount[$year] = array_filter($result[$details],function($co) use ($year){ return ($co['reg_year'] == $year && $co['bench_type'] == 'X'); }); $total = 0; $total = (int)(count($singlecount[$year])+count($divisioncount[$year])+count($fullcount[$year])+count($rpcount[$year])+count($mjccount[$year])+count($cocount[$year])); $htmlcontent .=" <tr> <td>".$year."</td> <td align=\"center\"> if(count($singlecount[$year])>0) { echo (count($singlecount[$year])); } else { echo "-"; } </td> <td align=\"center\"> if(count($divisioncount[$year])>0) { ".count($divisioncount[$year])." } else { "-" } </td> <td align=\"center\"> if (count($fullcount[$year]) > 0) { echo (count($fullcount[$year])); } else { echo "-"; } </td > < td align =\"center\"> if(count($rpcount[$year])>0) { echo (count($rpcount[$year])); } else { echo " - "; } </td> <td align=\"center\"> if(count($mjccount[$year])>0) { echo (count($mjccount[$year])); } else { echo " - "; } </td> <td align=\"center\"> if(count($cocount[$year])>0) { echo (count($cocount[$year])); } else { echo " - "; } </td> <td align=\"center\"> echo $total; </td> </tr>"; } } $htmlcontent .= "</tbody></table>"; $mpdf = new \Mpdf\Mpdf(); $mpdf->WriteHTML($htmlcontent); $mpdf->Output(); Waiting for FAST reply
Thanks Anes Now I am stumped this is far any help would be awesome This is what I have gotten so far, this is what it does right now is display the first column of the array as a header for each foreach loop then i've got the data displayed under each header in the loop but what i am trying to understand here is i am trying to get under each header it to have 4 columns or a number of my choosing. Heres an example of what i am trying to do. A airlie beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda This is an example of how it is being displayed right now A Airlie Beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda C Cannonvale Calen Crystal Brook Cremorne Chelona Campwin Beach Cape Hillsborough Conway Heres The Code i have so far. Code: [Select] <?php $file = "widget.csv"; @$fp = fopen($file, "r") or die("Could not open file for reading"); $outputArray = array(); while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE) { $outputArray[array_shift($shop)] = array_filter($shop); } print_r($outputArray); echo "\n<br />"; //display echo "<table>"; foreach ($outputArray as $alphabetical=>$value){ echo "<th><b>" . $alphabetical ."</b></th>"; echo "<tr>"; foreach ($value as $key){ echo "<td>" . $key . "</td>"; } echo "</tr>"; } echo "</table>"; echo "\n<br />"; ?> Heres my Csv File which i am using as an array in the code Quote A,Airlie Beach,Andergrove,Alexandra,Armstrong Beach,Alligator Creek,,,,,,,,,,,,,, B,Bucasia,Blacks Beach,Beaconsfield,Bakers Creek,Balberra,Bloomsbury,Breadalbane,Ball Bay,Belmunda,,,,,,,,,, C,Cannonvale,Calen,Crystal Brook,Cremorne,Chelona,Campwin Beach,Cape Hillsborough,Conway,,,,,,,,,,, D,Dows Creek,Dumbleton,Dolphin Heads,,,,,,,,,,,,,,,, E,Eimeo,Eton,Erakala,,,,,,,,,,,,,,,, F,Foulden,Foxdale,Flametree,Farleigh,Freshwater Point,,,,,,,,,,,,,, G,Glen Isla,Glenella,,,,,,,,,,,,,,,,, H,Homebush,Hampden,,,,,,,,,,,,,,,,, I,,,,,,,,,,,,,,,,,,, J,Jubilee Pocket,,,,,,,,,,,,,,,,,, K,Kinchant Dam,Kolijo,Koumala,Kuttabul,,,,,,,,,,,,,,, L,Laguna Quays,,,,,,,,,,,,,,,,,, M,McEwens Beach,Mackay,Mackay Harbour,Mandalay,Marian,Mia Mia,Middlemount,Midge Point,Mirani,Moranbah,Mount Charlton,Mount Jukes,Mount Julian,Mount Marlow,Mount Martin,Mount Ossa,Mount Pelion,Mount Pleasant,Mount Rooper N,Narpi,Nebo,Nindaroo,North Eton,,,,,,,,,,,,,,, O,Oakenden,Ooralea,,,,,,,,,,,,,,,,, P,Palmyra,Paget,Pindi Pindi,Pinevale,Pioneer Valley,Pleystowe,Preston,Proserpine,,,,,,,,,,, Q,,,,,,,,,,,,,,,,,,, R,Racecourse,Richmond,Riordanvale,Rosella,Rural View,,,,,,,,,,,,,, S,St Helens Beach,Sandiford,Sarina,Seaforth,Slade Point,Shoal Point,Shute Harbour,Shutehaven,Strathdickie,Sugarloaf,Sunnyside,,,,,,,, T,Te Kowai,The Leap,,,,,,,,,,,,,,,,, U,,,,,,,,,,,,,,,,,,, V,Victoria Plains,,,,,,,,,,,,,,,,,, W,Wagoora,Walkerston,Woodwark,,,,,,,,,,,,,,,, X,,,,,,,,,,,,,,,,,,, Y,Yalboroo,,,,,,,,,,,,,,,,,, Z,,,,,,,,,,,,,,,,,,, Now I am stumped this is far any help would be awesome This is what I have gotten so far, this is what it does right now is display each Header above each bit of data and spans across 5 columns for each foreach loop but what i am trying to understand here is i am trying to get the header then the data then another header and data and so on but only about 4 or number of my choosing grouped header/data but select how many are in each column up to 5 columns. Heres an example of what i am trying to do. A D K N S AlexandraHeadlands DickyBeach KingsBeach Nambour SandstonePoint Aroona Diddillibah KielMountain Ninderry ShellyBeach Doonan KundaPark NoosaHeads SippyDowns B Dulong Kuluin Ningi SunriseBeach Beachmere DeceptionBay Kilcoy NorthArm SunshineBeach BanksiaBeach Noosaville Scarborough Beerburrum E L Beerwah EerwahVale Landsborough O T Bellara Elimbah Tanawha Bellmere Eudlo M P TowenMountain Birtinya Eumundi Maleny Petrie Tewantin Bongaree Mapleton Palmview TwinWaters Bokarina F Marcoola Palmwoods BribieIslandArea Flaxton MarcusBeach Parklands U Buddina ForestGlen MaroochyRiver Parrearra UpperCaboolture Burnside Maroochydore PeregianBeach Buderim G Minyama Pinbarren V Burpengary GlassHouseMountains MoffatBeach PointArkwright Valdora BliBli Mons PelicanWaters H Montville PacificParadise W C Highworth Mooloolaba WeybaDowns CoolumBeach Hunchy Mooloolah Q Warana Caboolture MountainCreek WestWoombye CabooltureSouth I MountCoolum R Woombye Caloundra ImageFlat Morayfield Rosemount Woorim CastawaysBeach Mudjimba Redcliffe WamuranBasin Chevallum J Woodford CoesCreek WoodyPoint Cooroy Wamuran Currimundi Wurtulla X Y YandinaCreek Yandina Z This is an example of how it is being displayed right now A Airlie Beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda C Cannonvale Calen Crystal Brook Cremorne Chelona Campwin Beach Cape Hillsborough Conway Heres The Code i have so far. Code: [Select] <?php $file = "widget.csv"; @$fp = fopen($file, "r") or die("Could not open file for reading"); $outputArray = array(); $count = 0; while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE) { $outputArray[array_shift($shop)] = array_filter($shop); } echo "<table>"; foreach ($outputArray as $alphabetical=>$value){ echo "<th colspan='4'><b>" . $alphabetical ."</b></th>"; echo "<tr>"; foreach ($value as $key){ $afterkey=preg_replace('/\s+/','-',$key); if ($count == 4){ echo '</tr><tr><td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; $count = 0; }else{ echo '<td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; } $count++; } echo "</tr>"; $count = 0; } echo "</table>"; echo "\n<br />"; ?> Heres my CSV File: Quote A,Airlie Beach,Andergrove,Alexandra,Armstrong Beach,Alligator Creek,,,,,,,,,,,,,, B,Bucasia,Blacks Beach,Beaconsfield,Bakers Creek,Balberra,Bloomsbury,Breadalbane,Ball Bay,Belmunda,,,,,,,,,, C,Cannonvale,Calen,Crystal Brook,Cremorne,Chelona,Campwin Beach,Cape Hillsborough,Conway,,,,,,,,,,, D,Dows Creek,Dumbleton,Dolphin Heads,,,,,,,,,,,,,,,, E,Eimeo,Eton,Erakala,,,,,,,,,,,,,,,, F,Foulden,Foxdale,Flametree,Farleigh,Freshwater Point,,,,,,,,,,,,,, G,Glen Isla,Glenella,,,,,,,,,,,,,,,,, H,Homebush,Hampden,,,,,,,,,,,,,,,,, I,,,,,,,,,,,,,,,,,,, J,Jubilee Pocket,,,,,,,,,,,,,,,,,, K,Kinchant Dam,Kolijo,Koumala,Kuttabul,,,,,,,,,,,,,,, L,Laguna Quays,,,,,,,,,,,,,,,,,, M,McEwens Beach,Mackay,Mackay Harbour,Mandalay,Marian,Mia Mia,Middlemount,Midge Point,Mirani,Moranbah,Mount Charlton,Mount Jukes,Mount Julian,Mount Marlow,Mount Martin,Mount Ossa,Mount Pelion,Mount Pleasant,Mount Rooper N,Narpi,Nebo,Nindaroo,North Eton,,,,,,,,,,,,,,, O,Oakenden,Ooralea,,,,,,,,,,,,,,,,, P,Palmyra,Paget,Pindi Pindi,Pinevale,Pioneer Valley,Pleystowe,Preston,Proserpine,,,,,,,,,,, Q,,,,,,,,,,,,,,,,,,, R,Racecourse,Richmond,Riordanvale,Rosella,Rural View,,,,,,,,,,,,,, S,St Helens Beach,Sandiford,Sarina,Seaforth,Slade Point,Shoal Point,Shute Harbour,Shutehaven,Strathdickie,Sugarloaf,Sunnyside,,,,,,,, T,Te Kowai,The Leap,,,,,,,,,,,,,,,,, U,,,,,,,,,,,,,,,,,,, V,Victoria Plains,,,,,,,,,,,,,,,,,, W,Wagoora,Walkerston,Woodwark,,,,,,,,,,,,,,,, X,,,,,,,,,,,,,,,,,,, Y,Yalboroo,,,,,,,,,,,,,,,,,, Z,,,,,,,,,,,,,,,,,,, Hi... I tried to use foreach in displaying my table header, but I encountered problem when I tried to display data on the first row , my query only display the last Sum for the last Comp. here is my code: <html> <head> <title>Half Shell</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> <?php error_reporting(E_ALL ^ E_NOTICE); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <body> <form name="param" action="" method="post" onSubmit="return false"> <div id="fieldset_PS"> <?php echo "<table>"; $sql = "SELECT DISTINCT s.Comp FROM sales_order s, param_settings p WHERE s.Comp = p.Compounds ORDER BY s.Comp"; $res_comp = mysql_query($sql, $con); while($row_comp = mysql_fetch_assoc($res_comp)){ $Comp[] = $row_comp['Comp']; } echo "<th> </th>"; foreach($Comp AS $Comp){ echo "<th>$Comp</th>"; } echo "<tr> <td>Total Kg/Compound</td>"; $sql_sec = "SELECT SUM(TotalKg) AS TotalKg FROM sales_order WHERE Comp = '$Comp' ORDER BY Comp"; $res_sec = mysql_query($sql_sec, $con); while($row_sec = mysql_fetch_assoc($res_sec)){ $TotalKg[] = $row_sec['TotalKg']; } foreach($TotalKg AS $TotalKg){ echo "<td>$TotalKg</td> </tr>"; } ?> I also attach the correct output that should be and the result from my code. Thank you i am trying to use mpdf and i am trying to pass a for each loop. i was thinking equaling to a variable, but i saw you cant do that. Code: [Select] foreach($rows_details as $record_details){ echo "<td>$record_details[po_num]</td> <td>$record_details[warehouse_num]</td> <td>$record_details[quantity]</td> <td>$record_details[packages]</td> <td>$record_details[weight]</td> <td>$record_details[product_id]</td> <td>$record_details[pieces]</td> <td>$record_details[unit_price]</td> <td>$record_details[total_value]</td>"; } so i have to pass it through this any one have an idea Code: [Select] $html = ' <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> $mpdf->WriteHTML($html); $mpdf->Output(); exit; exit; Alright the issue that I am having is that I need to get multiple lines into a variable to output later in the code. my $pieces variable is not returning anything, much less missing parts of it, but even the text code is not returning.
foreach($packages as $pack) { $weight+=$pack->weight; $items_no++; $singleweight=$pack->weight; $length=$pack->length; $height=$pack->height; $width=$pack->width; $pieces .= '<piece actual_weight="'.$singleweight.'" length="'.$length.'" height="'.$height.'" width="'.$width.'">'; } if(!empty($post_code) && $weight>0 && $items_no>0) { $data='?shipment='.urlencode('<shipment weight_system="IMPERIAL" shipper_number="'.$this->shipper_number.'" destination_postal_code="'.$post_code.'" service_type="'.$service.'">'.$pieces.'</shipment>').'&token='.$this->token; // $woocommerce->add_message('Items No:'.$items_no.'- Postalcode:'.$post_code.'- '); $resp=file_get_contents($this->canpar_url.$data,false,$context);If I do this in another method that only requires a single line (getting the total weight and number of items) it works fine, but this does not return the proper shipping cost for low weight items. On a site where higher weight items is shipped the plugin works fine. However I need to modify it to work based on dimensions. The result I am looking for is something like this: https://www.canpar.com/XML/RatingXML.jsp?shipment= <shipment weight_system="IMPERIAL" shipper_number="42500047" destination_postal_code="M1M1M1" service_type="1"> <piece actual_wieght="7" length="24" height="24" width="24"/> <piece actual_wieght="5" length="10" height="12" width="14"/> </shipment> &token=WZHBRS4KQYNAusing an output system I can output weight, packs, length, width, height but it does not return anything for $pieces and obviously shipping costs because I am getting an invalid xml response. $woocommerce->add_message('Weight: '.$weight.' Packs: '.$items_no.' Shipping cost : '.$atts['total_charge'].' Pieces: '.$item_box.' Length: '.$length.' Width: '.$width.' Height: '.$height); Hey all.. I have been messing around with some code with a form that has checkboxes on them, and the option of selecting more than one checkbox to submit to the database. However, I keep getting the error," Warning: Invalid argument supplied for foreach() in (mydirectory)". I have followed many tutorials and I don't see anything I am doing differently that they are, so I'm sure this is a simple fix, of something I am overlooking, or I am just horrible at this (new person). Here is the snippet of the HTML code for the checkboxes. Code: [Select] <label> <input type="checkbox" name="project_list[]" value="chat"/> Chat Project (age 18+ requirement)</label> <br /> <label> <input type="checkbox" name="project_list[]" value="forums"/> Forums Project (age 18+ requirement)</label> <br /> <label> <input type="checkbox" name="project_list[]" value="content"/> Content/Editorial Project (postcasts, blogging, etc.)</label> <br /> <label> <input type="checkbox" name="project_list[]" value="technology" /> Technology Project</label> <br /> <label> <input type="checkbox" name="project_list[]" value="marketing"/> Marketing, Promotions and Publicity</label> <br /> <label> <input type="checkbox" name="project_list[]" value="designartwork"/> Design and Artwork</label> Here is the PHP code that I am using to do this. Code: [Select] include 'db.php'; mysql_select_db('skylers_training'); if($_POST['submit']) { $project_lists = $_POST['project_list']; foreach($project_lists as $list); //This is the line the code is getting the error on. And the section of the INSERT MYSQL CODE for this part. Code: [Select] $reginsert = mysql_query("INSERT INTO ... // the rest of the code (that works fine) follows this. '$list' // This is the line that is supposed to send data from the checklists to the database. When I submit the form, in addition to the error, nothing is submitted to the database table for the list (everything else works fine). Any insight into this, would be appreciated. Thanks! hey guys, I'm quite new to PHP and i was wondering if someone would be able to help me out with this. The code i have checks the database to see if a user has provided a Vimeo ID. If they haven't, $video_check will equal a line of html that says the user hasn't added any videos to their portfolio. If the a vimeo ID is present, i want $video_check to equal a bunch of html and css with a foreach function inside that is used to display the users videos from vimeo. The foreach function works fine when its not assigned to the $video_check variable. How do i structure it so that it displays correctly? If you click on videos on this page you might get a better idea of what i'm talking about. http://www.myfilmportfolio.ie/profile.php?id=33 and here is the code i'm having the problem with: /////// check if user has provided vimeo id ////////////////////////// $vimeoID = $row["vimeoID"]; $video_check=''; if (empty($vimeoID)){ $video_check = '<h3>'.$firstname .' has not added any videos to their portfolio</h3>'; } else{ $video_check = '<div id="stats"> <div style="clear: both;"></div> </div> <div id="wrapper"> <div id="embed"></div> <div id="thumbs"> <ul> <?php foreach ($videos->video as $video): ?> <li> <h4><?=$video->title?></h4> <a href="<?php echo $video->url ?>"> <img src="<?php echo $video->thumbnail_medium ?>" class="thumb" /></a> <p><?=$video->description?></p> <br /> </li> <?php endforeach ?> </ul> </div> </div>'; } if anyone could help me out id really appreciate it. Cheers, G This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355772.0 Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue? Heres my code: function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); dbarray($result); $fields_num = mysql_num_fields($result); echo "<table border='1'>"; // printing table headers echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; // printing table rows while($row = mysql_fetch_array($result)) { // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row AS $Cell) echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } echo "</table>"; mysql_free_result($result); } I have 2 rows inserted into my coords table. Just frustrated and ignorant to php. |