CodeIgniter Forums
Newbie in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Newbie in CodeIgniter (/showthread.php?tid=48956)



Newbie in CodeIgniter - El Forum - 02-02-2012

[eluser]akien[/eluser]
Hi guys,

I have a problem, I am a newbie in CodeIgniter so please understand me. I am a little confused with CodeIgniter so I seek help. My problem is I have this PHP code that has a text field for the $date_from and $date_to variable and a submit button. When I clicked the button the record will display base on the date(s) I entered. I have to convert it into a CodeIgniter or MVC pattern. Can anyone help me how I can convert the code on the next post, into a CodeIgniter way.

Thanks in advance and best regards


Newbie in CodeIgniter - El Forum - 02-02-2012

[eluser]akien[/eluser]
This is my code:

Code:
<?php
// db connection
$db = "mds_reports";

if($connect = mysql_connect("172.16.8.32", "mds_reports", "password"))
    $connect = mysql_select_db($db);
     else die("Unable to connect".mysql_error());

$date_from = $_POST['dfrom'];
$date_to = $_POST['dto'];
$name = $_POST['name'];
?>

<html>
<h1> PMIX Quantity Sold base on Category 2 </h1>
&lt;title&gt;PMIX!&lt;/title&gt;
&lt;body&gt;
  &lt;form name="PMIX" method="POST" action="PMIX.php"&gt;
   Date From &lt;input type="text" name="dfrom" id="dfrom"&gt;
   To &lt;input type="text" name="dto" id="dto"&gt;&lt;br /><br />
   Restaurant Name &lt;input type="text" name="name" id="name"&gt;  
   &lt;input type="submit" name="submit" value="submit"&gt;
  &lt;/form&gt;
  <table border="1">
  <tr>
   <th>Restaurant Code</th>
   <th>Restaurant Name</th>
   <th>Chicken Alc</th>
   <th>Chicken Evm</th>
   <th>Burger Alc</th>
   <th>Burger Evm</th>
   <th>Breakfast Alc</th>
   <th>Breakfast Evm</th>
   <th>Desserts</th>
   <th>Fries</th>
   <th>Evrdy McSavers</th>
   <th>Happy Meal</th>
   <th>Beverages</th>
   <th>Breakfast_Ba_P50</th>
   <th>Breakfast_Ba</th>
   <th>McSavers_P50</th>
   <th>Extras</th>
   <th>Upsize</th>
  </tr>

  &lt;?php
   if(isset($_POST['submit'])){
$sql = "SELECT restaurant_master.code, restaurant_master.name,

      SUM(CASE WHEN ItemMaster.Category2 = 'CHICKEN ALC'
       THEN OrderItemHistory.Quantity END) AS CHICKEN_ALC,

      SUM(CASE WHEN ItemMaster.Category2 = 'CHICKEN EVM'
       THEN OrderItemHistory.Quantity END) AS CHICKEN_EVM,

      SUM(CASE WHEN ItemMaster.Category2 = 'BURGER ALC'
       THEN OrderItemHistory.Quantity END) AS BURGER_ALC,

      SUM(CASE WHEN ItemMaster.Category2 = 'BURGER EVM'
       THEN OrderItemHistory.Quantity END) AS BURGER_EVM,

      SUM(CASE WHEN ItemMaster.Category2 = 'BREAKFAST ALC'
       THEN OrderItemHistory.Quantity END) AS BREAKFAST_ALC,
  
      SUM(CASE WHEN ItemMaster.Category2 = 'BREAKFAST EVM'
       THEN OrderItemHistory.Quantity END) AS BREAKFAST_EVM,

      SUM(CASE WHEN ItemMaster.Category2 = 'DESSERTS'
       THEN OrderItemHistory.Quantity END) AS DESSERTS,

      SUM(CASE WHEN ItemMaster.Category2 = 'FRIES'
       THEN OrderItemHistory.Quantity END) AS FRIES,

      SUM(CASE WHEN ItemMaster.Category2 = 'EVRDY MCSAVERS'
       THEN OrderItemHistory.Quantity END) AS EVRDY_MCSAVERS,

      SUM(CASE WHEN ItemMaster.Category2 = 'HAPPY MEAL'
       THEN OrderItemHistory.Quantity END) AS HAPPY_MEAL,

      SUM(CASE WHEN ItemMaster.Category2 = 'BEVERAGES'
       THEN OrderItemHistory.Quantity END) AS BEVERAGES,

      SUM(CASE WHEN ItemMaster.Category2 = 'BREAKFAST BA P50'
       THEN OrderItemHistory.Quantity END) AS BREAKFAST_BA_P50,

      SUM(CASE WHEN ItemMaster.Category2 = 'BREAKFAST BA'
       THEN OrderItemHistory.Quantity END) AS BREAKFAST_BA,

      SUM(CASE WHEN ItemMaster.Category2 = 'MCSAVERS P50'
       THEN OrderItemHistory.Quantity END) AS MCSAVERS_P50,

      SUM(CASE WHEN ItemMaster.Category2 = 'EXTRAS'
       THEN OrderItemHistory.Quantity END) AS EXTRAS,

      SUM(CASE WHEN ItemMaster.Category2 = 'UPSIZE'
       THEN OrderItemHistory.Quantity END) AS UPSIZE

      FROM mds_orders
       INNER JOIN OrderItemHistory
        ON mds_orders.PKID = OrderItemHistory.OrderFKID
       INNER JOIN ItemMaster
        ON OrderItemHistory.ItemFKID = ItemMaster.PKID
       INNER JOIN restaurant_master
        ON mds_orders.RestaurantID = restaurant_master.pkid

      WHERE mds_orders.OrderDate BETWEEN '".$date_from." 00:00:00' AND '".$date_to." 23:59:59'
       AND restaurant_master.name = '$name'

      GROUP BY restaurant_master.code, restaurant_master.name";
echo "Date selected: ".$date_from." - ".$date_to."</p>";
     echo "Restaurant name: ".$name."</p>";
     $result = mysql_query($sql);
     $num_rows = mysql_num_rows($result);
     echo "The number of rows is ".$num_rows."</p>";
     $i = 0;
     if (mysql_num_rows($result) >0) {
     while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){
      $csv .= $row['code'].",".
        $row['name'].",".
        $row['CHICKEN_ALC'].",".
        $row['CHICKEN_EVM'].",".
        $row['BURGER_ALC'].",".
        $row['BURGER_EVM'].",".
        $row['BREAKFAST_ALC'].",".
        $row['BREAKFAST_EVM'].",".
        $row['DESSERTS'].",".
        $row['FRIES'].",".
        $row['EVRDY_MCSAVERS'].",".
        $row['HAPPY_MEAL'].",".
        $row['BEVERAGES'].",".
        $row['BREAKFAST_BA_P50'].",".
        $row['BREAKFAST_BA'].",".
        $row['MCSAVERS_P50'].",".
        $row['EXTRAS'].",".
        $row['UPSIZE'].","."<br>";
    ?&gt;

    <tr>
     <td>&lt;?php echo $row['code'];?&gt;</td>
     <td>&lt;?php echo $row['name'];?&gt;</td>
     <td>&lt;?php echo $row['CHICKEN_ALC'];?&gt;</td>
     <td>&lt;?php echo $row['CHICKEN_EVM'];?&gt;</td>
     <td>&lt;?php echo $row['BURGER_ALC'];?&gt;</td>
     <td>&lt;?php echo $row['BURGER_EVM'];?&gt;</td>
     <td>&lt;?php echo $row['BREAKFAST_ALC'];?&gt;</td>
     <td>&lt;?php echo $row['BREAKFAST_EVM'];?&gt;</td>
     <td>&lt;?php echo $row['DESSERTS'];?&gt;</td>
     <td>&lt;?php echo $row['FRIES'];?&gt;</td>
     <td>&lt;?php echo $row['EVRDY_MCSAVERS'];?&gt;</td>
     <td>&lt;?php echo $row['HAPPY_MEAL'];?&gt;</td>
     <td>&lt;?php echo $row['BEVERAGES'];?&gt;</td>
     <td>&lt;?php echo $row['BREAKFAST_BA_P50'];?&gt;</td>
     <td>&lt;?php echo $row['BREAKFAST_BA'];?&gt;</td>
     <td>&lt;?php echo $row['MCSAVERS_P50'];?&gt;</td>
     <td>&lt;?php echo $row['EXTRAS'];?&gt;</td>
     <td>&lt;?php echo $row['UPSIZE'];?&gt;</td>
    <tr>

  &lt;?php  
    }}}
  ?&gt;

  </table>
   &lt;form name="extract" method="POST" action="export_PMIX.php"&gt;
   &lt;input type="hidden" name="export_PMIX_dfrom" id="data" value="&lt;?=$date_from;?&gt;"&gt;
   &lt;input type="hidden" name="export_PMIX_dto" id="data" value="&lt;?=$date_to;?&gt;"&gt;
   &lt;input type="hidden" name="export_PMIX_name" id="data" value="&lt;?=$name;?&gt;"&gt;
   &lt;input type="submit" name="extract" value="extract"&gt;
   &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;



Newbie in CodeIgniter - El Forum - 02-02-2012

[eluser]JuanitoDelCielo[/eluser]
I don't want to be rude but check this tutorial

http://ellislab.com/codeigniter/user-guide/tutorial/index.html

It's simple, easy, short. You can learn the base of CI.


Newbie in CodeIgniter - El Forum - 02-05-2012

[eluser]akien[/eluser]
Okay. Thank you for the reference. Best Regards.