Jump to content

thara

Members
  • Posts

    604
  • Joined

Everything posted by thara

  1. my php version is 5.3.10. Problem was solved using second method you have provided. Now I had another issue when I trying to use default time. I set default time like this. $def_times = array('06:00:00', '11:30:00'); // default Then I can get this message: Line 30 is : $closeTime = $times[2];
  2. @Barand, I can get a fetal error when I using above code. This is my updated code: if (isset($_POST['next-step'])) { $restaurantId = 2; $def_times = array('06:30:00', '10:30:00'); // default $sql = "INSERT INTO business_hours ( restaurant_id , day , open_time , close_time ) VALUES (?,?,?,?)"; $stmt = $mysqli->prepare($sql); $stmt->bind_param('iiss', $restaurantId, $dayNo, $openTime, $closeTime); foreach ($_POST['openclose'] as $dayNo => $times) { $dayNo = (int)$dayNo; if ($times[1]==-1) { // closed $times[1] = $times[2] = '00:00:00'; } elseif (empty(array_filter($times))) { $times = $def_times; // set the times to the stored defaults } else { $def_times = $times; // save the times as the default times } $openTime = $times[1]; $closeTime = $times[2]; $stmt->execute(); if ($times[3]!='') { $openTime = $times[3]; $closeTime = $times[4]; $stmt->execute(); } } } This is the error message: line 24 is $times = $def_times; // set the times to the stored defaults
  3. @Barand, I went on your logic. But I am confusing how to figure this out. I tried it something like this. foreach ( $_POST['openclose'] as $day => $time) { //echo "$day and $time<br>"; foreach ($time as $open => $close) { echo "$day - $open, $close<br>"; if($open == '-1') { } } } But, I am not sure how to create insert query for this and don't know how to insert "closed" day into mysql... Hope you may help me out. Thank you.
  4. @Barand, your solution is very flexibility. Great idea. Thank you very much. Can you kindly tell me how to process this HTML form and how to make INSERT query? Do I need to change my database structure? Thank you.
  5. Yes I understand what you have said. Actually I am assuming opening hours is same for everyday. If I use different hours I may use different way to do this, but at this time I need to do this by assuming opening hours is same. If its so, can you tell me how can I make the Insert query for this? Thank you.
  6. @Barand, Thank you for your info. Here I have attached an image to see you how I going to use these date in my website. http://www.tiikoni.com/tis/view/?id=570f668 And this is how I get these info from users http://www.tiikoni.com/tis/view/?id=3d00416 So, can you tell me what is the best way to this? Thank you.
  7. @Ch0cu3r, Thank you for your answer. But My question is I am getting two days from users, like Monday, Saturday with opening and closing time. So Now I need to insert into mysql all the records between this two days. Eg: Monday,9am,10pm Tuesday,9am,10pm Wednesday, 9am, 10am and until Saturday (To user secondly selected date)
  8. I'm working on a website involving local restaurants, and one thing I need to do is store hours of operation. This is how I get operating hours from business owners. // Sunday - Saturday 11AM - 6PM $_POST['from'], $_POST['to'], $_POST['opening_time'], $_POST['closing_time'] Then I need to store these operating hours in `MySql` like below format. - Sunday: 9am - 11pm - Monday: 9am - 11pm - Tuesday: 9am - 11pm - Wednesday: 9am - 11pm - Thursday: 9am - 11pm - Friday: 9am - 11pm - Saturday: 9am - 11pm This is how my mysql table looks like. CREATE TABLE business_hours ( id integer NOT NULL PRIMARY KEY, restaurant_id integer NOT NULL, day integer NOT NULL, open_time time, close_time time ) I am not sure How to do this in php. so can anybody pointed my to right direction here? Any idea would be greatly appreciated. Thank you.
  9. I am trying to display some images dynamically from a mysql table. This is what I tried it with PHP and its working for me. // Fetch all the records: while ($stmt->fetch()) { $html = " <div class='row-fluid custom'>\n"; $html .= " <div class='span6'>\n"; $html .= " <img src='images/{$image}'>\n"; $html .= " </div>\n"; $html .= " </div>\n"; //Add images to array $images[] = $html; } And this is the markup from about PHP: <div class='row-fluid custom'> <div class='span6'> <img src='images/cond-1.png'> </div> </div> <div class='row-fluid custom'> <div class='span6'> <img src='images/cond-2.png'> </div> </div> <div class='row-fluid custom'> <div class='span6'> <img src='images/cond-3.png'> </div> </div> <div class='row-fluid custom'> <div class='span6'> <img src='images/cond-4.png'> </div> </div> But my problem is, now I need to modify above Markup to like this. <div class="row-fluid custom"> <div class="span6"> <img src="images/cond-1.png"> </div> <div class="span6"> <img src="images/cond-2.png"> </div> </div> <div class="row-fluid custom"> <div class="span6"> <img src="images/cond-3.png"> </div> <div class="span6"> <img src="images/cond-4.png"> </div> </div> Can anybody tell me how I create like that markup using php? Hope somebody may help me out. Thank you.
  10. One more question. When I use this mysql query, I need to get image ID for each image. Can you tell me how I get image id with each image? This is how I tried it. But its only get one image id. SELECT s.id , s.name , s.description , i.id AS imageId , GROUP_CONCAT(i.image_path,i.image) AS images FROM services s LEFT JOIN images i ON i.service_id = s.id GROUP BY s.id The result from above query look like this. *************************** 1. row *************************** id: 12 name: dfafdf description: <p>afdsfdfadf</p> imageId: 18 images: ../upload/services/12_1435570281.jpg,../upload/services/12_1435570270.jpg,../upload/services/12_1435570260.jpg,../upload/services/12_1435570251.jpg *************************** 2. row *************************** id: 13 name: dfafdfghdhgdhg description: <p>dsfasfdfdasfadf</p> imageId: 20 images: ../upload/services/13_1435570313.jpg,../upload/services/13_1435570293.jpg *************************** 3. row *************************** id: 14 name: sadfasfd df awerw dsfa description: <p>dsfadfadsf dfsfaf dsfds ffgfg r3t retg ntmyrh thfdasa</p> imageId: NULL images: NULL 3 rows in set (0.06 sec)
  11. Thanks @Barand, how would be the PHP for my table. ? Meanwhile I changed above query to set image path with the images, like this. SELECT s.id , s.name , s.description , GROUP_CONCAT(i.image_path,i.image) as images FROM services s LEFT JOIN images i ON i.service_id = s.id GROUP BY s.id
  12. I am trying to populate HTML table with the data comes from my database. Here I have stored "services" in my table. each service may have multiple images. So when populating the table it should have 3 table cells one for "service name" and second for "discription" and third one for images. This is my sql query looks like: $prep_stmt = " SELECT s.id , s.name , s.description , i.image , i.image_path FROM services s LEFT JOIN images i ON i.service_id = s.id"; This is how my while look like this: while ($stmt->fetch()) { $html = "<tr>\n"; $html .= " <td><input type='checkbox'></td>\n"; $html .= " <td>\n"; $html .= " <a href='' class='name'>{$name}</a>\n"; $html .= " </td>\n"; $html .= " <td class='view_html'>{$description}</td>\n"; $html .= " <td>\n"; --- My images should be display here ---- $html .= " </td>\n"; $html .= "</tr>\n"; //Add output to array $output[] = $html; } My problem is How I display multiple images in one table cell? If one service have only one image then I can do it, but it has multiple images then I am not sure how to do it. Hope somebody may help me out. Thank you.
  13. I tried it using two tables like this : CREATE TABLE IF NOT EXISTS image_category( category_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(60) NOT NULL, PRIMARY KEY (category_id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO image_category (name) VALUES ('service'), ('management'); CREATE TABLE IF NOT EXISTS image_info( image_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT, category_id INT(4) NOT NULL, image VARCHAR(80) NOT NULL, image_path VARCHAR(150) NOT NULL, extention VARCHAR(10) NOT NULL, image_size VARCHAR(10) NOT NULL, dimension VARCHAR(15) NOT NULL, mime_type VARCHAR(20) NOT NULL, alt_text TEXT DEFAULT NULL, added_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (image_id), UNIQUE (image) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; But not sure how it related profile images and service images? Do I not need to store profile images in separate table like this? Why I trying do is, I need to get all my images into one table.. Any idea would be greatly appreciated. Thank you.
  14. I have two mysql tables named "management" and "services". "management" table have fields: - id - name - designation - description - added_date "services" table have fields: - id - name - description - added_date Every persons in "management" table should have one image. (their profile image) and in "services" table it will have multiple services and each service should have multiple images. So my question is, How I get these images to one table named "image_info" and how they separate each other? Hope somebody may help me out. Thank you.
  15. @Barand, Yes its working nicely. Thank you very much for the great solution like this. I am trying and trying to get the logic of this function and how its work, but still I couldn't.... If you have a time, kindly explain this function and how its working. It will be greatly helped me. Thank you very much again.
  16. @Barand, Still I couldn't get what you have said?
  17. @Barand, I tried with your updated answer. This is rendered HTML from it. <ul> <li>Dogs</li> <ul> <li>Bulldog</li> <li>Bullmastiff</li> <li>Chow Chow</li> <li>Cocker Spaniel</li> <li>German Shepherd</li> <li>Gordon Setter</li> </ul> <li>Cats</li> <ul> <li>American Bobtail</li> <li>Balinese</li> <li>Birman</li> <li>British Shorthair</li> <li>Burmese</li> </ul> <li>Birds</li> </ul> But I want to have my HTML something like this. <ul class="list-unstyled categorychecklist "> <li><input type="checkbox" value=""> Dogs <ul class="children"> <li><input type="checkbox" value=""> Bulldog</li> <li><input type="checkbox" value=""> Bullmastiff</li> <li><input type="checkbox" value=""> Chow Chow</li> <li><input type="checkbox" value=""> Cocker Spaniel</li> <li><input type="checkbox" value=""> German Shepherd</li> <li><input type="checkbox" value=""> Gordon Setter</li> </ul> </li> <li><input type="checkbox" value=""> Cats <ul class="children"> <li><input type="checkbox" value=""> American Bobtail</li> <li><input type="checkbox" value=""> Balinese</li> <li><input type="checkbox" value=""> Birman</li> <li><input type="checkbox" value=""> British Shorthair</li> <li><input type="checkbox" value=""> Burmese</li> </ul> </li> <li><input type="checkbox" value=""> Birds <ul class="children"></li></ul> </li> </ul> With your function, I confuse how to separate main and nested <ul> with their classes. Any idea would be greatly appreciating. Thanks in advance.
  18. @Muddy_Funster, Can you tell me how I modify this section of your code to match with my while loop. $orderTemp = array(); foreach ($results as $row){ if(count($row) == 3 ){ $orderTemp[$row['Lev1']][$row['Lev2']][] = $row['Lev3']; } if(count($row) == 2 ){ $orderTemp[$row['Lev1']][$row['Lev2']] = null; } } This is how my while loop looks like. I am using mysqli prepared Statements for my select query. $prep_stmt = "SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3 FROM categories AS t1 LEFT JOIN categories AS t2 ON t2.parent = t1.category_id LEFT JOIN categories AS t3 ON t3.parent = t2.category_id WHERE t1.name = 'Pets'"; $stmt = $mysqli->prepare($prep_stmt); if ($stmt) { // Execute the prepared query. $stmt->execute(); $stmt->store_result(); // get variables from result. $stmt->bind_result($lev1, $lev2, $lev3); $categories = array(); // Fetch all the records: while ($stmt->fetch()) { $categories[$lev1][$lev2][] = $lev3; } }
  19. Thank you for your answer. Its working for me. But problem is when I trying to add CSS classes to these <ul> list. Can you tell me how can we add these classes? Thank you.
  20. This is my updated code and output is still same. So what would be the problem? echo '<ul class="list-unstyled categorychecklist ">'; foreach($categories['Pets'] as $lev2_category => $lev2_categories) { echo '<li><input type="checkbox" value="" /> ' . $lev2_category; if(!empty($lev2_categories) && $lev2_categories != NULL) { echo '<ul class="children">'; foreach($lev2_categories as $lev3_value) { echo '<li><input type="checkbox" value="" /> '.$lev3_value.'</li>'; } echo '</ul>'; } else { echo '</li>'; //echo '<li><input type="checkbox" value="" /> ' . $lev2_category.'</li>'; } } echo '</ul>'; Thanks in advance.
  21. this is how my category data look like.. mysql> SELECT t1.name AS lev1, -> t2.name as lev2, -> t3.name as lev3 -> FROM categories AS t1 -> LEFT JOIN categories AS t2 -> ON t2.parent = t1.category_id -> LEFT JOIN categories AS t3 -> ON t3.parent = t2.category_id -> WHERE t1.name = 'Pets'; +------+---------+-------------------+ | lev1 | lev2 | lev3 | +------+---------+-------------------+ | Pets | Dogs | Bulldog | | Pets | Dogs | Bullmastiff | | Pets | Dogs | Chow Chow | | Pets | Dogs | Cocker Spaniel | | Pets | Dogs | German Shepherd | | Pets | Dogs | Gordon Setter | | Pets | Cats | American Bobtail | | Pets | Cats | Balinese | | Pets | Cats | Birman | | Pets | Cats | British Shorthair | | Pets | Cats | Burmese | | Pets | Birds | NULL | | Pets | Fish | NULL | | Pets | Reptile | NULL | +------+---------+-------------------+ 14 rows in set (0.06 sec)
  22. When using @Barand answer I can get an output something similar to this. But I don't need to have Main category in this case its "Pets". PetsDogsBulldog Bullmastiff Chow Chow Cocker Spaniel German Shepherd Gordon Setter CatsAmerican Bobtail Balinese Birman British Shorthair Burmese Birds Fish Reptile
  23. Thank you for all 3 replies and all 3 answers working me partly. From first two answers, I can get the same output. Problem is, if main category doesn't have its sub category, then echoing an empty checkbox to that main category. So I tried to avoid from it something like this, But it doesn't work for me. check this screenshot : http://img42.com/IHEz6+ echo '<ul class="list-unstyled categorychecklist ">'; foreach($categories['Pets'] as $lev2_category => $lev2_categories) { echo '<li><input type="checkbox" value="" /> ' . $lev2_category; if(!empty($lev2_categories)) { echo '<ul class="children">'; foreach($lev2_categories as $lev3_value) { echo '<li><input type="checkbox" value="" /> '.$lev3_value.'</li>'; } echo '</ul></li>'; } else { echo '<li><input type="checkbox" value="" /> ' . $lev2_category.'</li>'; } } echo '</ul>';
  24. I have used hierarchical data modal to store animals in database. Animal have only main and subcategory, and this is the result when I retrieving the Full Tree of Animals. SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3 FROM categories AS t1 LEFT JOIN categories AS t2 ON t2.parent = t1.category_id LEFT JOIN categories AS t3 ON t3.parent = t2.category_id WHERE t1.name = 'Pets'; +------+------+-------------------+ | lev1 | lev2 | lev3 | +------+------+-------------------+ | Pets | Dogs | Bulldog | | Pets | Dogs | Bullmastiff | | Pets | Dogs | Chow Chow | | Pets | Dogs | Cocker Spaniel | | Pets | Dogs | German Shepherd | | Pets | Dogs | Gordon Setter | | Pets | Cats | American Bobtail | | Pets | Cats | Balinese | | Pets | Cats | Birman | | Pets | Cats | British Shorthair | | Pets | Cats | Burmese | +------+------+-------------------+ 11 rows in set (0.04 sec) My question is, I'm having trouble displaying this information as an unordered list. My expecting result would be something like this: <ul class="list-unstyled categorychecklist "> <li><input type="checkbox" value=""> Dogs <ul class="children"> <li><input type="checkbox" value=""> Bulldog</li> <li><input type="checkbox" value=""> Bullmastiff</li> <li><input type="checkbox" value=""> Chow Chow</li> <li><input type="checkbox" value=""> Cocker Spaniel</li> <li><input type="checkbox" value=""> German Shepherd</li> <li><input type="checkbox" value=""> Gordon Setter</li> </ul> </li> <li><input type="checkbox" value=""> Cats <ul class="children"> <li><input type="checkbox" value=""> American Bobtail</li> <li><input type="checkbox" value=""> Balinese</li> <li><input type="checkbox" value=""> Birman</li> <li><input type="checkbox" value=""> British Shorthair</li> <li><input type="checkbox" value=""> Burmese</li> </ul> </li> <li><input type="checkbox" value=""> Birds</li> </ul> Hope somebody may help me out. Thanks in advance.
  25. Thank you... I understood and I do need to change my table structure. But with my existing table structure I got a solution with mysql FIND_IN_SET() string function and this is how my SELECT query look like. select t.match_info_id, t.user_id, group_concat(distinct a.name) as body_types, group_concat(distinct b.name) as hair_colors, group_concat(distinct c.name) as ethnicity from match_info as t inner join body_type as a on find_in_set(a.id,t.body_types) inner join hair_color as b on find_in_set(b.id,t.hair_colors) inner join ethnicity as c on find_in_set(c.id,t.ethnicity) group by t.match_info_id, t.user_id This is the output from above query: +---------------+---------+-------------------------------------+---------------------------+---------------------------------------------+ | match_info_id | user_id | body_types | hair_colors | ethnicity | +---------------+---------+-------------------------------------+---------------------------+---------------------------------------------+ | 1 | 1 | Skinny,Large | Silver/White,Partial Gray | Asian | | 2 | 2 | Skinny,Husky,Few extra pounds,Large | Silver/White | White/Caucasian,Mixed Race,Pacific Islander | +---------------+---------+-------------------------------------+---------------------------+---------------------------------------------+ 2 rows in set (1.87 sec) Any idea would be greatly appreciated regarding this query... Thank you.
×
×
  • Create New...

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.