Need help with the query to select all

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 2095 Views - Last Post: 26 August 2015 - 08:41 PM Rate Topic: -----

#1 sinux12   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 06-December 14

Need help with the query to select all

Posted 03 August 2015 - 11:34 PM

I'm creating this app which enables user to list out jobs which have been planned according to the woven machine. I originally designed this to work machine wise but now the client requests that he need to be able to get all the details in one page as well as machine wise. So I basically used an IF ... ELSE condition it works but my problem is that initially the variable is empty until the form get submitted so is there way to over come this error.

My full code is below, Also the form get submitted to it self.

Any help on this is appreciated.

<?php
/**
 * Created by PhpStorm.
 * User: SiNUX
 * Date: 5/8/2015
 * Time: 12:23 PM
 */

session_start();
include_once("iConnect/iConnect_db.php");

if(($_SESSION["uType"] != "jPlanner") && ($_SESSION["uType"] != "admin")){
    session_unset();
    session_destroy();

    header("location:login.php?login=Logged out, Due to unauthorised access !!");
}

if($_POST["loom"] == "all"){
    $getData = "SELECT * FROM jobdetails WHERE jobDate = :jobDate";
    $getQuery = $dbConnect ->prepare($getData);
    $getQuery -> bindParam(':loom',$_POST["loom"]);
    $getQuery -> bindParam(':jobDate', $_POST["jobDate"]);
    $getQuery ->execute();

}else{
    $getData = "SELECT * FROM jobdetails WHERE loom = :loom AND jobDate = :jobDate";
    $getQuery = $dbConnect ->prepare($getData);
    $getQuery -> bindParam(':loom',$_POST["loom"]);
    $getQuery -> bindParam(':jobDate', $_POST["jobDate"]);
    $getQuery ->execute();
}


?>
<!DOCTYPE html>
<html>
<head>
    <title>Job List</title>
    <style type="text/css">
        table, th, td{
            border-color:#999999;
            border-width: thin;
            border-style: solid;
        }
        table{
            border-collapse: collapse;
        }
    </style>

    <!-- Need Jquery -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <!--Load Script and Stylesheet -->
    <script type="text/javascript" src="calendar/jquery.simple-dtpicker.js"></script>
    <link type="text/css" href="calendar/jquery.simple-dtpicker.css" rel="stylesheet" />

    <script type="text/javascript">
        function valDelete(){
            var del = confirm("Are you sure you want to delete this record ?");
            return del;
        }
    </script>

</head>
<body>
	<form enctype="multipart/form-data" action="" method="post" style="margin-bottom:1;">

	  <div align="right" style="background-color:#CCC">
          <input type="text" id="jobDate" name="jobDate" value="---Select Date---" />
          <script type="text/javascript">
              $(function(){
                  $('*[name=jobDate]').appendDtpicker(
                      {
                          'dateFormat' : 'DD/MM/YYYY',
                          'dateOnly': true,
                          'closeonselected': true,
                          'autodateonstart': false
                      }
                  );
              });
          </script>
	    <select name="loom" onchange="this.form.submit()">
	      <option>---- Select Loom ----</option>
          <option value="all">All</option>
	      <option value="B">B</option>
	      <option value="C">C</option>
	      <option value="D">D</option>
	      <option value="E">E</option>
	      <option value="G">G</option>
	      <option value="H">H</option>
        </select>
      </div>
	</form>
<table width="100%">
                  <tr>
                    <th width="9%" scope="col">Job No</th>
                    <th width="13%" scope="col">Hours</th>
                    <th width="28%" scope="col">Total Hours Remaining</th>
                    <th width="23%" scope="col">Shift</th>
                    <th width="26%" scope="col">Loom</th>
                  </tr>
           <?php while ($row = $getQuery -> fetch(PDO::FETCH_ASSOC))  {?>
                  <tr align="center">
                    <td><?php echo $row["jobno"]; ?></td>
                    <td><?php echo $row["prodHours"]; ?></td>
                    <td><?php echo $row["totalTimeLeft"] ?></td>
                    <td><?php echo $row["shift"]; ?></td>
                    <td><?php echo $row["loom"]; ?></td>
                  <?php if(($_SESSION["uType"] != "jPlanner") && ($_SESSION["uType"] != "admin")) { ?>
                    <td width="14%"><input type="button" value="Edit" disabled /></td>
                    <td width="14%"><input type="button" value="Assign Machine" disabled /></td>
                    <td width="14%"><input type="button" value="Add Packing"  disabled /></td>
                    <td width="12%"><input type="button" value="Delete" disabled /></td>
                  <?php } else { ?>
                      <td width="14%"><a href="#" onclick="window.open('../UniversalPlaningSystem/editPlan.php?id=<?php echo $row["jNo"] ?>', 'Edit job', 'location=no, status=no, toolbar=no, resizable=no, width=800, height=750')"><input type="button" value="Edit Job" /></a></td>
                      <td width="14%"><a href="#" onclick="window.open('../UniversalPlaningSystem/CandF_PlanAddNew.php?id=<?php echo $row["jNo"] ?>', 'Assign Cut & Fold Machine', 'location=no, status=no, toolbar=no, resizable=no, width=800, height=750')"><input type="button" value="Assign Cut & Fold Machine" /></a></td>
                      <td width="14%"><a href="#" onclick="window.open('../UniversalPlaningSystem/Plan_Packing.php?id=<?php echo $row["jNo"] ?>', 'Add Packing', 'status=no, location=no, width=220, height=270')"><input type="button" value="Add Packing" /></a></td>
                      <td width="12%"><a href="deleteRecord.php?id=<?php echo $row["jNo"] ?>" onclick="return valDelete()"><input type="button" value="Delete" /></a></td>
                  <?php } ?>
                  </tr>
           <?php } ?>
</table>
</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: Need help with the query to select all

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: Need help with the query to select all

Posted 04 August 2015 - 12:08 AM

Quote

my problem is that initially the variable is empty until the form get submitted

which variable? I see more than one.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6554
  • View blog
  • Posts: 26,569
  • Joined: 12-December 12

Re: Need help with the query to select all

Posted 04 August 2015 - 12:32 AM

if($_POST["loom"] == "all"){

You are assuming that this $_POST element exists. Look into the isset() and empty() functions. But every single example I've ever seen demonstrates some way to check if the form has been submitted so I am very surprised that this is stumping you.

Note that the width and align attributes of table elements are no longer supported in HTML5. Use CSS instead.

This post has been edited by andrewsw: 04 August 2015 - 12:34 AM

Was This Post Helpful? 0
  • +
  • -

#4 sinux12   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 06-December 14

Re: Need help with the query to select all

Posted 04 August 2015 - 02:52 AM

View PostDormilich, on 04 August 2015 - 12:38 PM, said:

Quote

my problem is that initially the variable is empty until the form get submitted

which variable? I see more than one.


$_POST["loom"]


That one
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: Need help with the query to select all

Posted 04 August 2015 - 02:57 AM

check if itís set. if not, use a default value.
Was This Post Helpful? 0
  • +
  • -

#6 sinux12   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 06-December 14

Re: Need help with the query to select all

Posted 04 August 2015 - 04:06 AM

View PostDormilich, on 04 August 2015 - 03:27 PM, said:

check if itís set. if not, use a default value.


I just disabled the error massage 'cos it's working as I intended it to be.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6554
  • View blog
  • Posts: 26,569
  • Joined: 12-December 12

Re: Need help with the query to select all

Posted 04 August 2015 - 04:21 AM

OP said:

..but now the client requests ..

You are being employed to write code? You should not be ignoring an error, that is a terrible approach. You should be working out was is wrong with, or missing from, your code and fixing it. You should be writing robust and stable code.
Was This Post Helpful? 1
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2031
  • View blog
  • Posts: 6,202
  • Joined: 15-January 14

Re: Need help with the query to select all

Posted 04 August 2015 - 09:44 AM

Quote

I just disabled the error massage 'cos it's working as I intended it to be.

Ha! Right, don't fix the errors, just ignore them. Fantastic solution you've got there. Maybe we should start doing that here, instead of helping people fix their errors we can just show them how to ignore the messages. I seriously hope that no one is paying you to do this, because you're not giving them their money's worth. They expect software without errors.
Was This Post Helpful? 1
  • +
  • -

#9 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2542
  • View blog
  • Posts: 10,187
  • Joined: 03-December 12

Re: Need help with the query to select all

Posted 04 August 2015 - 11:03 AM

Post #5
Was This Post Helpful? 0
  • +
  • -

#10 sinux12   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 06-December 14

Re: Need help with the query to select all

Posted 06 August 2015 - 11:25 AM

View PostArtificialSoldier, on 04 August 2015 - 10:14 PM, said:

Quote

I just disabled the error massage 'cos it's working as I intended it to be.

Ha! Right, don't fix the errors, just ignore them. Fantastic solution you've got there. Maybe we should start doing that here, instead of helping people fix their errors we can just show them how to ignore the messages. I seriously hope that no one is paying you to do this, because you're not giving them their money's worth. They expect software without errors.


First of all error is happening due to the $_POST value is not set form get submitted to it self once that variable receives that value it works just fine tried using a default which wont work the way I want it to work.

And error is not major thing it only says loom variable is not set I'm not braking it but making it work if you people are so enlightened give a better answer than start world war over hiding a simple error. I tried the isset which actually didn't work and can't set default it has to be empty when the page loads.

And now I'm starting doubt that you people read the whole code before giving an answer. I came here to get an answer which I was unable to find after many tires and what you people do just beat around bushes with out giving direct answer when I do something which I think was right from my point of view you people just jump on oh u hide a error .. .. blah, blah, blah ..

Also before going in to freak mode read the problem say what should have been doen then go there don't do it before that it's pathetic.
Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2031
  • View blog
  • Posts: 6,202
  • Joined: 15-January 14

Re: Need help with the query to select all

Posted 06 August 2015 - 11:31 AM

Quote

First of all error is happening due to the $_POST value is not set form get submitted to it self once that variable receives that value it works just fine tried using a default which wont work the way I want it to work.

A default isn't the answer, isset is the answer.

Quote

I tried the isset which actually didn't work

Then you didn't do it the right way.


Instead of saying "isset didn't work", maybe post the code. If it didn't work then the most likely reason is because you didn't use it correctly, so post what you did and ask why it didn't work instead of just assuming that you have the right answer and ignoring error messages is OK.

You need to wrap your entire if/else in another if statement that uses isset to check if the post variable is set. That's the answer.
Was This Post Helpful? 1
  • +
  • -

#12 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6554
  • View blog
  • Posts: 26,569
  • Joined: 12-December 12

Re: Need help with the query to select all

Posted 06 August 2015 - 11:53 AM

I am going to quote myself from post #3:

View Postandrewsw, on 04 August 2015 - 07:32 AM, said:

You are assuming that this $_POST element exists. Look into the isset() and empty() functions. But every single example I've ever seen demonstrates some way to check if the form has been submitted so I am very surprised that this is stumping you.

This makes me, and others I suspect, reluctant to repeat information which is so readily available. Checking that a form has been submitted is one of the first (primary) tasks of a PHP script and there are tonnes of examples you could find and attempt to apply.

Then, as ArtificialSoldier says, you could post your attempt and explain the errors or problems you are encountering.
Was This Post Helpful? 1
  • +
  • -

#13 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3795
  • View blog
  • Posts: 13,738
  • Joined: 08-August 08

Re: Need help with the query to select all

Posted 06 August 2015 - 12:15 PM

View Postsinux12, on 06 August 2015 - 02:25 PM, said:

And now I'm starting doubt that you people read the whole code before giving an answer. I came here to get an answer which I was unable to find after many tires and what you people do just beat around bushes with out giving direct answer when I do something which I think was right from my point of view you people just jump on oh u hide a error .. .. blah, blah, blah ..

Well, I for one am amazed that anyone is willing to help you at all. Your code and your posts demonstrate poor knowledge of PHP in general, and an even worse work ethic. This is what gives PHP a bad reputation in the coding community: You mix languages (PHP, HTML, CSS, Javascript/jQuery), your code is outdated, repetitive, and you seem to know nothing of functions or classes, let alone any kind of design pattern. To make things worse, you want the answer spoon fed to you.

You're being paid for this? :no:

If you simply admitted to being an absolute beginner who needs guidance from the first line of code on, that would be a different story. Of course, then you'd need to demonstrate a strong willingness to accept and use that guidance. This would mean starting from scratch.
Was This Post Helpful? 0
  • +
  • -

#14 sinux12   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 06-December 14

Re: Need help with the query to select all

Posted 06 August 2015 - 11:15 PM

Thank you for the study on me. I learned PHP by my self from books I managed to buy yeah my style might be old and might not have knowledge on functions or classes or I don't like to use them. Any way thank you for your reply and yeah I'm getting some scratch for this you got problem with that old or new I'm using what I've gained and I'm not going to give it for free. But his fellow PHP programmer I will help in any way I can code wise or idea wise.

Spoon fed no I don't need that I got this far with out any once help but met some good guys who helped me 'cos in my country studying costs a fortune and I'm unable to do that so I study what I can don't act like you know me 'cos you don't you can't tell something about a person by looking at his code.

And you talk about missing code yeah I do that 'cos it works for me if you have better thing show me I'll study that if it suits me I'll adopt it.

But regardless of your comment ArtificialSoldier and andrewsw your last two answers helped me a lot to find a solution for that error will post the code once I perfect it in my old style.

This post has been edited by Dormilich: 07 August 2015 - 12:43 AM

Was This Post Helpful? 0
  • +
  • -

#15 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2031
  • View blog
  • Posts: 6,202
  • Joined: 15-January 14

Re: Need help with the query to select all

Posted 07 August 2015 - 10:18 AM

Quote

don't act like you know me 'cos you don't you can't tell something about a person by looking at his code.

That's not true at all. You can tell a lot about someone by the quality of the things they produce. For example, the fact that you decided that hiding the error message was the best solution instead of fixing the error does say something about you. That you write code to process a form without checking if a form was submitted says something. I don't know your name, or your age, or what kind of childhood you had, but I know a couple things about how you design and write code and solve problems.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3