Jump to content

thara

Members
  • Content Count

    536
  • Joined

  • Last visited

Community Reputation

5 Neutral

About thara

  • Rank
    Prolific Member
  • Birthday 02/05/1983

Profile Information

  • Gender
    Male
  • Location
    Panda

Contact Methods

  • Skype
    tharangagamage
  1. Sir, I tried it in this way: //Insert other post image: if(!empty($_SESSION['other-image'])) { $record_vals = []; foreach ($other_image as $name => $values) { foreach ($values as $k => $v) { $record_vals[$k][$name] = $v; } } $query = "INSERT INTO post_image ( image_type , image , thumb , image_path , sort_order , added_date ) VALUES (?,?,?,?,?,NOW())"; $stmt = $mysqli->prepare($query); $stmt->bind_param('isssi', $type , $image , $thumb , $path , $sort_order ); $order=2; foreach ($record_vals as $k = > $v) { foreach ($v as $column => $value) { $image = $record_vals[$k]['img'][$value]; $path = $record_vals[$k]['path'][$value]; $type = $record_vals[$k]['type'][$value]; $thumb = $record_vals[$k]['thumb'][$value]; $sort_order = $order; $stmt->execute(); } ++$order; } } Can you tell me what is the mistake I have done?
  2. Yes sir. Its exactly what I needed. Now I want to insert these data into mysql. Sir, can you tell me how to do it? I tried it something like this, but it doesn't work. //Insert other post image: if(!empty($_SESSION['other-image'])) { $query = "INSERT INTO post_image ( image_type , image , thumb , image_path , sort_order , added_date ) VALUES (?,?,?,?,?,NOW())"; $stmt = $mysqli->prepare($query); $stmt->bind_param('isssi', $type , $image , $thumb , $path , $sort_order ); $order=2; foreach ($_SESSION['other-image'] as $value) { foreach ($value as $v) { $type = $_SESSION['other-image']['type'][$v]) $image = $_SESSION['other-image']['img'][$v]) $thumb = $_SESSION['other-image']['thumb'][$v]) $path = $_SESSION['other-image']['path'][$v]) $sort_order = $order; $stmt->execute(); } ++$order; } }
  3. This is my array. It has stored images data. [other-image] => Array ( [img] => Array ( [0] => 1526973657.jpg [1] => 1526973661.jpg [2] => 1526973665.jpg ) [path] => Array ( [0] => ../post-upload/1/ [1] => ../post-upload/1/ [2] => ../post-upload/1/ ) [type] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [thumb] => Array ( [0] => thumb_1526973661.jpg [1] => thumb_1526973665.jpg [2] => thumb_1526973668.jpg ) ) Now I want to delete an image and it's all related data from sub arrays. (path, type, thumb data) This is how I tried it in php: $delkey = $_POST['key']; if(in_array($delkey, $_SESSION['other-image']['img'])){ $imgkey = array_search($delkey, $_SESSION['other-image']['img']); if($imgkey) unset($_SESSION['other-image']['img'][$imgkey]); //file path $fp = UPLOAD_DIR.$nextId."/".$delkey; unlink($fp); } As I did, its only deleting element form 'img' array, but I want to delete related data from other arrays too. Can anybody tell me how to do this? Thank you.
  4. mysql> SHOW VARIABLES LIKE '%char%'; +--------------------------+------------------------------------------------+ | Variable_name | Value | +--------------------------+------------------------------------------------+ | character_set_client | cp850 | | character_set_connection | cp850 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | cp850 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | I:\wamp64\bin\mysql\mysql5.7.9\share\charsets\ | +--------------------------+------------------------------------------------+ 8 rows in set (1.15 sec) This is how I connect to PHP: $mysqli = new MySQLi(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Verify the connection and // Set the character set: if ($mysqli->connect_error) { //echo $mysqli->connect_error; //unset($mysqli); echo 'Database connection failed...' . 'Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error; exit(); } else { // Establish the encoding. $mysqli->set_charset('utf8'); } Insert is ok with PHP. but problem is, when using command line interface.
  5. I am trying to insert data from my mother language (Sinhala) into my mysql table. But MySQL displays my chracters as question marks. This is how I test it: CREATE DATABASE sinhala_test; USE kindheart; ALTER DATABASE sinhala_test CHARACTER SET utf8 COLLATE utf8_general_ci CREATE TABLE IF NOT EXISTS `category` ( `category_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name_si` VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL, `description_si` TEXT COLLATE utf8_unicode_ci NOT NULL, `last_update` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `category` VALUES (1,'පොත් පත් සහ පාසල් උපකරණ','නවතම පොත් පත් අවශ්‍යතා ඇතුළු සියළුම පාසැල් හා අධ්‍යාපන මෙවලම්.',NOW()); This is what can I get from MySQL command line: mysql> select * from category\G *************************** 1. row *************************** category_id: 1 name_si: ???? ??? ?? ????? ????? description_si: ???? ??????? ??????? ????????. ????/????????? ????? ?????? ?????? ?? ???????? ??????. last_update: 2018-05-20 11:11:20 Can anybody tell me how can I fix this problem? NOTE: When inserting from phpMyAdmin its correctly work.
  6. I'm trying to add owl carousel for each bootstrap tab. Carousel in the first tab is loading perfectly, but when user clicks on second tab, owl carousel items are not loading. That mean on second tab it displays empty space instead of displaying carousel items. My HTML is something like this: <!-- Nav tabs --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#female" aria-controls="female" role="tab" data-toggle="tab">Female</a></li> <li role="presentation"><a href="#male" aria-controls="male" role="tab" data-toggle="tab">Male</a></li> </ul> <!-- Tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="female"> <div data-items="1" data-lg-items="7" data-margin="20" class="owl-carousel" data-autoplay='false'> <div> <a href="#"> <div> <img src="images/profile/profile1.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile2.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile3.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> </div> </div> <div role="tabpanel" class="tab-pane" id="male"> <div data-items="1" data-lg-items="7" data-margin="20" class="owl-carousel" data-autoplay='false'> <div> <a href="#"> <div> <img src="images/profile/profile1.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile2.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile3.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> </div> </div> </div> This is my JS looks like: var plugins = { bootstrapTabs: $(".tabs"), owl: $(".owl-carousel") }; if (plugins.owl.length) { var i; for (i = 0; i < plugins.owl.length; i++) { var c = $(plugins.owl[i]), responsive = {}; var aliaces = ["-", "-xs-", "-sm-", "-md-", "-lg-"], values = [0, 480, 768, 992, 1200], j, k; for (j = 0; j < values.length; j++) { responsive[values[j]] = {}; for (k = j; k >= -1; k--) { if (!responsive[values[j]]["items"] && c.attr("data" + aliaces[k] + "items")) { responsive[values[j]]["items"] = k < 0 ? 1 : parseInt(c.attr("data" + aliaces[k] + "items")); } if (!responsive[values[j]]["stagePadding"] && responsive[values[j]]["stagePadding"] !== 0 && c.attr("data" + aliaces[k] + "stage-padding")) { responsive[values[j]]["stagePadding"] = k < 0 ? 0 : parseInt(c.attr("data" + aliaces[k] + "stage-padding")); } if (!responsive[values[j]]["margin"] && responsive[values[j]]["margin"] !== 0 && c.attr("data" + aliaces[k] + "margin")) { responsive[values[j]]["margin"] = k < 0 ? 30 : parseInt(c.attr("data" + aliaces[k] + "margin")); } } } c.owlCarousel({ autoplay: c.attr("data-autoplay") === "true", loop: c.attr("data-loop") !== "false", items: 1, dotsContainer: c.attr("data-pagination-class") || false, navContainer: c.attr("data-navigation-class") || false, mouseDrag: "false", nav: c.attr("data-nav") === "true", dots: c.attr("data-dots") === "true", dotsEach: c.attr("data-dots-each") ? parseInt(c.attr("data-dots-each")) : false, animateIn: c.attr('data-animation-in') ? c.attr('data-animation-in') : 'fadeIn', animateOut: c.attr('data-animation-out') ? c.attr('data-animation-out') : 'fadeOut', responsive: responsive, navText: [] }); } $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { e.target // newly activated tab e.relatedTarget // previous active tab $(".owl-carousel").trigger('refresh.owl-carousel'); }); } So can anybody tell me how to fix this issue? Hope somebody may help me out. Thank you.
  7. thara

    Hiya everyone

    Welcome to PHPFreaks!
  8. thara

    Hello Everyone

    Welcome to PHPFreaks!
  9. thara

    Congratulations to Barand on 1000 likes

    I too love Barand, I know, my contributions is over 100 likes for him. Congratulations Sir!!! Anyway anybody have a looked at this profile?
  10. Basically I am having an array something like below, this array has number of categories and sub, sub sub categories. $categories = array( array('id' => 1, 'parent' => 0, 'name' => 'Category'), array('id' => 2, 'parent' => 1, 'name' => 'Category A'), array('id' => 3, 'parent' => 1, 'name' => 'Category B'), array('id' => 4, 'parent' => 1, 'name' => 'Category C'), array('id' => 5, 'parent' => 1, 'name' => 'Category D'), array('id' => 6, 'parent' => 1, 'name' => 'Category E'), array('id' => 7, 'parent' => 2, 'name' => 'Subcategory F'), array('id' => 8, 'parent' => 2, 'name' => 'Subcategory G'), array('id' => 9, 'parent' => 3, 'name' => 'Subcategory H'), array('id' => 10, 'parent' => 4, 'name' => 'Subcategory I'), array('id' => 11, 'parent' => 9, 'name' => 'Subcategory J'), ); Using this array I have created a nested <ul>. This is the recursive function I have used for : foreach ($categories as $category) { $id = $category['id']; $parent = $category['parent']; $name = $category['name']; //echo $name."<br>"; $cats[$parent][$id] = $name; } function displayList(&$cats, $parent, $current=0, $level=0) { switch ($level) { case 0: $class = "level_1 has_sub no_active"; $a_class = "c1"; break; case 1: $class = "level_2 has_sub no_active"; $a_class = "c2"; break; case 2: $class = "level_3 has_sub no_active"; $a_class = "c3"; break; } if ($parent==0) { foreach ($cats[$parent] as $id=>$nm) { if (isset($cats[$id])) { displayList($cats, $id, $current); } } } else { echo "<ul class='$class'>\n"; foreach ($cats[$parent] as $id=>$nm) { $clear = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode($nm))); $pageName = strtolower(str_replace(' ', '-', $clear)); $link = $pageName.'.php'; echo "<li><a href='$link' class='$a_class $sel'><span>$nm</span></a>\n"; if (isset($cats[$id])) { displayList($cats, $id, $current, $level+1); } echo '</li>'; } echo "</ul>\n"; } } Look at that function, I have created a link for each category. Category name itself has used as page name. (Removing by special chars.) My question is, when this function executing I want to create folders for level one categories. Those category names should be used as folder names. Example from above array: category_a category_b category_c category_d category_e So, every sub category pages should be inside these parent category folders. Can I know is this possible in this function? Thank you.
  11. thara

    Myphpadmin - DD MM YYYY ?

    It doesn't matter. You can retrieve dates in whatever format you want Eg: SELECT DATE_FORMAT('2017-01-23', '%d/%m/%Y') But, you must however save all dates using the YYYY-MM-DD format as that is the only format that mysql date fields can accept (it is also the only format where you can sort into date order)..
  12. thara

    Modal button including php page

    Since you are using bootstrap, You can easily create very smart and flexible dialog boxes with the Bootstrap modal plugin. Try this, if(isset($_SESSION['steamid'])){ echo '<button type="button" class="btn btn-lg btn-inverse btn-custom waves-effect waves-light" data-toggle="modal" data-target="#myModal"> Host a lobby </button>'; } Don't use <a> tag with button. Modal HTML: <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> ... modal contents here .... </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
  13. thara

    I need urgent help with my prepare statement!

    Here you need get_result() try it like this: if (!empty($date1_raw) && !empty($date2_raw)) { $sql = "SELECT * FROM costs WHERE costdate BETWEEN ? AND ? AND userid= ? ORDER BY costdate"; $stmt = $conn->prepare($sql); if ($stmt) { $stmt->bind_param("ssi", $date1_raw, $date2_raw, $session_id); $stmt->execute(); $result = $stmt->get_result(); printf("Number of rows: %d.\n", $stmt->num_rows); while($row = $result->fetch_assoc()) { echo $row['subcategory']; echo $row['costname']; // Added "€" sign infront of price !--> echo "€ " . $row['price']; echo $row['info']; // Added Date Function to convert format !--> echo date( "d/m/y",strtotime ($row['costdate'])); } } } NOTE: It is best practice to explicitly list every column you want returned instead of using select *, there are situations where you might want to save time and omit certain columns from the results.
  14. I am trying to remove folders and its files and sub folders using php. This is how I tried it. $dir = "../../images/$category_id/$delId"; $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach($files as $file) { if ($file->isDir()){ rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } rmdir($dir); This is working on php 5.5+, but is doesn't work in php 5.2.17. This is the error can I get when it running on php 5.2.17 Can anybody tell me how I get it to work on 5.2 also. Thank you.
  15. thara

    Hours:Minutes drop downs

    You have got an elegant solution for this from your other post. But, if you want to get hours and minutes into separate dropdown, we can do it something like this, <select name="hour"> <?php for ($i=0; $i<=23; $i++){ $i = sprintf('%02d', $i); echo "<option value='".$i."'>" . $i ."</option>\n"; } ?> </select> <select name="minutes"> <?php for ($i=0; $i<=59; $i++){ $i = sprintf('%02d', $i); echo "<option value='".$i."'>" . $i ."</option>\n"; } ?> </select>
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.