Jump to content

moondran

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by moondran

  1. Thanks Barand, works perfect!!
  2. Hi Guys/Girls I have a table that looks like this: id plant_id week year reading 1 2 20 2012 10 2 3 20 2012 12 3 2 19 2012 10 I'm using thi to get the total between weeks, it works perfect: $sql_week1 = "SELECT plant_id, SUM(reading) FROM `table_diesel_site` WHERE ((week BETWEEN '$first_week' AND '$last_week') AND year='$year') GROUP BY plant_id "; My question is, how can I get the total for week 19 and total of week 20 and the total of week 19+ week 20 in one query to echo them like: Total week 19 = Total week 20= Grand Total = The string above gives me the grand total but I need the total of week 19 and 20 aswell. Can it be done in one query or will I have to create 3 seperate querys for each week? Thanks
  3. moondran

    Group By

    Thanks allot!!
  4. moondran

    Group By

    Hi All I have a table containing the id's of items (field name item_id). These items gets booked out and in again and the record stored. So in my table I will have something like this. Id item_id status date 1 2 in 2012-03-12 2 3 out 2012-04-15 3 2 out 2012-05-12 What I want to display is what is the status of the last entry of an item. Currently what I have is SELECT `status` FROM `table` GROUP BY item_id ORDER BY date DESC But this gives me the first entry of an item and not the last. And even when I change DESC to ASC it still gives me the first entry. Thanks for the help
  5. Thanks for the reply cyber. An switch might work yes, the only problem I have is that I don’t know what $tank_name value will be. So in short what I’m looking for is a method to test the value of $tank_name if it is the same as in one the pervious statement in the loop keep bg the same else change it to something new.
  6. $currentSRNum = substr_replace($currentSRNum, 'JO', 0, 0);
  7. Hi Guys/Girls I’m using a while loop to get data from a database, The databsa consists of a tank_name and tank_reading fields. What I want to do is to make the bgcolor of each tank_name te same color. So in other words when the tank_name change then the bgcolor must change but all the tank_names that are the same must have the same bgcolor. In example: this comes out of the db via while loop Tank 1 bgcolor yellow Tank 2 bgcolor red Tank 3 bgcolor blue Tank 2 bgcolor red Tank 2 bgcolor red Tank 1 bgcolor yellow $sql1 = "select a.*, b.plant_nr AS plant_name, d.plant_nr AS tank_name from `table_tankReading` AS a LEFT JOIN `db_plant` AS b ON b.id=a.plant_id LEFT JOIN `db_plant_inc` AS c ON (c.plant_id=a.plant_id AND c.plant_category='Diesel Tank Type') LEFT JOIN `db_plant` AS d ON d.id=tank WHERE (a.tank_reading_mine_id='$mine_id' AND a.tank_reading_month='$month_string' AND a.tank_reading_year='$year') ORDER BY a.tank+0, a.date_tank_reading "; $result1 = $mysqli->query($sql1); while($myrow1 = $result1->fetch_assoc()){ $tank_name = $myrow1["tank_name"]; echo" <tr bgcolor="$bg"><td>$tank_name </td></tr>"; } Thanks for the help
  8. moondran

    MYSQL Join

    Hi Guys I'm having a little problem with fetching data from 2 or more tables from the same db. I'm using 2 methodes: 1. $sql_emp = "SELECT a.*, b.points FROM `table_users` AS a, `table_points` AS b WHERE b.user_id=a.id ORDER BY a.surname "; 2. $sql_emp = "SELECT a.id,a.name,a.surname,b.points FROM a LEFT JOIN b ON b.user_id = a.id "; Methode 1 is working but my problem is when table b has no entry it's not returning anything. In other words say there is 10 employees stored in table a and only 2 employees have points entries in table b my query only return 2. Is there a way to join tables that I can get all the entries from table a even if there is no entries in table b?
  9. Try using xajax it’s a simple and fast to understand, http://xajaxproject.org/
  10. The code is irrelevant to question really, All I want to know if there is a way to echo or use the variable if you have the following: In a nut shell this is what I have. A textField called Monday_$emp_id in a while loop. Lets say I’m working with the 1st employee for the example. So on my input page I will have this. $Monday_1 = “100”; I know I have a variable on the input page called $Monday_unknownNumber but the unknownNumber is the id of the employee so I can get it. $emp_id=”1”; The unknown number above is always the id of an employee so I can get it. So for me to echo it or use it I need to do something like the following. echo “$Monday_{$emp_id}”; this is the part I’m looking for, this code obviously doesn’t work.
  11. Hi Guys need some help with this: On my first page I generate a form with a while loop from a table with employees. I’m not going to paste my whole code for fast reading: While($myrow = $result ->fetch_assoc()){ $emp_id = $myrow[“id”]; $emp_name = $myrow[“name”]; $display .= <<<EOF_ <input type="hidden" name="monday_$emp_id" id=" monday_$emp_id" value="$monday" /> <input type="hidden" name="tuesday_$emp_id " id="tuesday_$emp_id" value="$tuesday " /> EOF_; } I give each field the name ie. monday_$emp_id to give them each unique names: My question is how do I recall those variables on my input page? On my input page I use a foreach to get all the variables but need to enter them into a table with the fields (emp_id, monday,tuesday) etc. The problem is that the variables on the input page is ie. $Monday_23 and the number 23 can be anything depending on the employee id. I have managed with explode() to get the emp_id and tried to use $Monday = $Monday_{$emp__id}; but that doesn’t seem to work. Thanks
×
×
  • 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.