kekkaishi 18 Junior Poster

ive removed the quotes and thats starting to look a lot better, i just need it to put the result ("exact") in place of the stock("3").

just to clarify, u dont want to display the quantity in the table, instead, you want it to be either exact, out of stock or In stock

for example,
A9190 SENSOR ASSY 90DEG 450MM 0233170500 TTC Exact

if this is the case, u might wanna concentrate on this part of ur code.

echo "<td width='20%'>".$result[stock]."</td>";

hint: u want this row to display Exact if $row = $qty.. so on n so forth..

kekkaishi 18 Junior Poster

also u might wanna check the following in ur code

while($result = mysql_fetch_array($query));
}
if(!$qresult || $row['stock'] < $qty) {
//I DONT THINK U NEED "" , try echo $out;
echo "$out";
}
elseif(!$qresult || $row['stock'] > $qty) {
echo "$in";
//change to echo $in;  remove quote
}
elseif(!$qresult || $row['stock'] = $qty) {
echo "$exact";
//remove quote echo $exact;
}
kekkaishi 18 Junior Poster

http://www.dandesign.co.uk/test/stock.php?partnum=a9190&quantity=3&Submit=Search

where the number three is i want it to say exact or not in stock etc and not where it is at the min

ok, let's try to go step by step. i need u to stay here with for a while :D im sure i'll be able to help ya out.

first of all, tell me, what are you trying to achieve here

$string = ("SELECT * FROM table WHERE stock >= $qty AND part = \"$pt\"")
or die("Please enter a part number");

m particularly trying to understand the "or die(..)" part

kekkaishi 18 Junior Poster

Im very new to php, but im trying to create a bit of code that you type in the part number and quantity you want and it returns the part number and the word "limited" if its the same "not enough" if it's less than and "in stock" if its more than, im having trouble getting it to say the word in the end column where i want it.

Here is the code, but please remember im very new to it so it might be a complete mess

<form id="search" name="form" action="stock.php" method="get">
<input type="text" name="partnum" width="50"/>
<input type="text" name="quantity" width="50"/>
<input type="submit" name="Submit" value="Search" />
</form>

<?php
include("namefile");

  $pt = @$_GET['partnum'] ;
  $qty = @$_GET['quantity'] ;

// check for an empty string and display a message.
if ($qty == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

// check for an empty string and display a message.
if ($pt == "")
  {
  echo "<p>Please enter a search...</p>";
  exit;
  }

//connect to mysql
$connection = mysql_connect($host,$account,$password)
    or die ("Couldn't connect to server");

//select which database you want to edit
$db = mysql_select_db("dbname",$connection)
    or die ("Couln't connect to database");

$out = "Out of stock";
$in = "In Stock";
$exact = "Exact";   

// SQL Query  
$string = ("SELECT * FROM table WHERE stock >= $qty AND part = \"$pt\"")
    or die("Please enter a part number");

$qresult = mysql_query("SELECT part,stock FROM table WHERE stock >= $qty AND part = \"$pt\"");
$query = mysql_query($string) or die (mysql_error());
    $row = mysql_fetch_array($qresult);
    { …
kekkaishi 18 Junior Poster

Ok.
usertype (in the println that I commented next to) will always print 0 because it is in the constructor. You added an action listener to the button, but you didn't click the button yet. So after the code I posted above adds the action listener, it immediately goes and prints "usertype" - but you haven't clicked the button yet, and therefore usertype has not been changed yet, so it prints 0!

Basically, I don't think you don't have a problem, you just think you have a problem. If you *really* want to verify that "usertype" is being set correctly, just do a System.out.println(getUsertype()); inside of the actionPerformed method at some point after you set the usertype.

with all due respect mate, and i'm sure its annoying as hell to listen to one person like me babbling all day, I have done all these. That System.out.println(usertype) or System.out.println(getUsertype) was added inside actionPerformed to check if the value is there and it is. I think i havent clarified my exact problem here.
In the Main class I am creating a new object of LogUI, say logUI object, and am adding it to the desktopPane. Now i see two text fields and a button as expected. I am entering a correct username n a password and then I click the button. Now, my expected outcome is the button is setting the usertype in the LogUI class and if I call the logUI.getUsertype(), i am expecting it to have maintained the …

kekkaishi 18 Junior Poster

Wrong. Run my code if you don't believe me.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RandomTest extends JPanel implements WindowListener{
	
	int random = 0;
	public RandomTest(){
		JButton button = new JButton("Click me");
		
		button.addActionListener(new ActionListener(){
		
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				random = 5;
				System.out.println("Variable random is " + random);
			}
		});
		this.add(button);
	}
	
	public static void main(String[] args){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		RandomTest test = new RandomTest();
		frame.add(test);
		frame.addWindowListener(test);
		frame.setSize(300,300);
		frame.setVisible(true);
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Window is closing. Variable random  = " + random);
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	
}

oi mate, thanks for the reply. i see that the value is maintained in ur code, but im still having trouble figuring out what I have done wrong. could you point me in a bit more like "idiots guide to.." style :D thannks

kekkaishi 18 Junior Poster

check s:

String s = rs.getString("userType");
System.out.println("|"+s+"|");
usertype = Integer.parseInt(s);

hey thanks for ya reply. But I've already done this. In the Login class. see line 13.

usertype = Integer.parseInt(rs.getString("userType"));

and when i call to this value from Log class, see line 15 in class Log, I get the value. and if i print out the usertype within the actionPerformed method, the value is there. But if I call it outside this method, the value is not there. meaning I cannot retrieve the usertype value in the Log class.

say for example the following code.

Log logObject = new Log();
int x = logObject.getUserType();

// int x is always 0. this is my problem.
kekkaishi 18 Junior Poster

and really this code is going over the head. can u explain ur requirements. I am also not an expert but i think i can help with something like this.

kekkaishi 18 Junior Poster

start quote:

C:\Documents and Settings\Administrator\Desktop\course\src\course.java:37: illegal start of expression
 }
 ^
C:\Documents and Settings\Administrator\Desktop\course\src\course.java:38: reached end of file while parsing
}2 errors

Process completed.

this is the error and i cant understand.
already change the getNumberOfStudents to getnum....
but same error generated

try changing getnumber to getNumber, and please post the Course class.
ps: the code u posted doesnt have a 37th line.... just wonderin aloud. the actual program in ur pc might have. so..

kekkaishi 18 Junior Poster

HI ! GUYS WILL YOU PLEASE HELP ME IN SOLVIG A SIMPLE QUESTION RELATING TO JAVA RMI
MY QUESTION IS HOW TO START RMI REGISTRY PROGRAMATICALY
with out TYPING IN CMD(command prompt ) start rmiregistry ?

maybe, LocateRegistry.createRegistry(port) :icon_rolleyes:

kekkaishi 18 Junior Poster
import java.util.*;
public class course
{
 static Scanner sc=new Scanner(System.in);
 public static void main(String[]args)
 {
 	 String name,students,addStudent;
 	 int numberOfStudents;
 	 String courseName,getName,getStudents;
 	 int getnumberOfStudents;
 	 
 	
 	Course course1=new Course("C++");
 	Course course2=new Course("Java");
 	
 	course1.addStudent("Peter");
 	course1.addStudent("Brian");
 	course1.addStudent("Anne");
 	
 	course2.addStudent("Peter");
 	course1.addStudent("Steve");
 	
 	System.out.println("Num of student in course1:"+course1.getnumberOfStudents());
 	
 	String[]students=course1.getStudents();
    for (int i = 0; i < course1.getNumberOfStudents(); i++)
	

 	System.out.println("Num of student in course2:"+course2.getnumberOfStudents());
 	
 	String[]students=course2.getStudents();
    for (int i = 0; i < course2.getNumberOfStudents(); i++)
	

 }
}
what is the problem it does not generate the output the numOfStudents who take c++ n JAVA.please explain to me. i am not good in array...

I dont understand ur code but from what I understood, the problem COULD be here.

System.out.println("Num of student in course1:"+course1.getnumberOfStudents());

From the for loop, i understand that the method name is getNumberOfStudents. with a capital N. however, the same mistake is there in the second one also, meanin course2.getnumberOf....

if its not the problem, u might wanna post the code for the class Course.

kekkaishi 18 Junior Poster

i dont know where to put my getValidString validation when i ask the user if he wants to judge another

public class JudgingApp
{
    public static void main(String args[])
    {
        Scanner sc= new Scanner(System.in);

        DecimalFormat df = new DecimalFormat("0.##");//format decimals to 2 decimal places

        //These variables hold the max and min numbers.
        double maxNumber = Double.MIN_VALUE; // Maximum number
        double minNumber = Double.MAX_VALUE; // Minimum number



        //allow user to execute the code multiple times
        String choice = "y";

        while(choice.equalsIgnoreCase("y"))
        //while(getValidString())
        {
        //variables
        double realTotalNumber,number,totalNumber = 0;

            //for loop to ask user to enter scores
            for(int n = 1; n < 9; n++)
            {
                //get input from user
                number = getNumberWithinRange(sc,"Enter score #" + n + ": ", 1.00, 10.00);

                //records max and min numbers
                if (number > maxNumber)
                {
                    maxNumber = number;
                }//end if
                if (number < minNumber)
                {
                    minNumber = number;
                }//end if

                //adds and records numbers inputted from user
                totalNumber += number;
            }//end forloop


        //total of user inputs not including the min and max numbers entered
        realTotalNumber = totalNumber -(minNumber+maxNumber);

        //prints out the following
        System.out.println("\nThe minimum score is " + df.format(minNumber));
        System.out.println("The maximum score is " + df.format(maxNumber));
        System.out.println("The total score is " + df.format(realTotalNumber));

        //prompts user to continue
        System.out.print("\nJudge another? (y/n): ");
        choice = sc.next();
        System.out.println();
        }//end while

    }//end MainMethod()



//method to validate the scores to be the correct data type and to be within the correct range
public static double getNumberWithinRange(Scanner sc, String prompt, double min, double max)
    {
        double d = 0; …
kekkaishi 18 Junior Poster

In actionPerformed, you create a new "Login", not a new "Log". Why didn't you post your Login class? (Post it :) )

PS: It seems to me from the way that you created a new "Login" and then called a method identical to one I see in the Log class, that Login extends Log, and that in the Login class, you did not override the getUserType method. But that's just a guess. I'm pretty sick right now, but post your class and someone will take a look at it.

thanks mate,
nope, Log is not an extension of Login class, in fact, Log actually extends JInternalFrame, here is the two classes.

log class

public class LogUI extends JInternalFrame{
    private JTextField user = new JTextField(10);
    private JPasswordField pass = new JPasswordField(10);
    private JPanel panel = new JPanel();
    private JButton button = new JButton("Login");
    private int usertype;
    
public LogUI(){
        panel.add(user);
        panel.add(pass);
        panel.add(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Login lg = new Login(user.getText(), pass.getText());
                usertype = lg.getUsertype();
            }
        });
        this.add(panel);
        this.setTitle("Login");
        this.pack();
        this.setVisible(true);
    }
    public int getUsertype() {
        return usertype;
    }

and the Login class

public class Login {
    private int usertype;
    private ResultSet rs;
    private Statement st; 
    public Login(String user, String pass){
        try{
            SgmDb db = new SgmDb();
            st = db.connectToDB().createStatement();
            String query = "SELECT username, password, userType FROM user WHERE username='"+user+"' AND password = '"+pass+"'";
            st.executeQuery(query);
            rs = st.getResultSet();
            while(rs.next()){
                usertype = Integer.parseInt(rs.getString("userType"));
            }
            rs.last();
            if(rs.getRow()==0){
                JOptionPane.showMessageDialog(null, "Wrong username or password");
            }
        }catch(Exception e){ …
kekkaishi 18 Junior Poster

Hi,

ive been trying to assign a value to a variable from within the ActionPerformed method, but the value seems to be lost as soon as ActionPerformed method ends. here's the code

public class Log{
private JTextField user = new JTextField(10);
private JPasswordField pass = new JPasswordField(10);
private int usertype=0;
private JPanel panel = new JPanel();

public Log(){

        panel.add(user);
        panel.add(pass);
        panel.add(button);

button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              Login logs = new Login(user.getText(), pass.getText());
              //this one is querying the database and getting an int value for user type. 
                usertype = logs.getUsertype();
            }
        });
//some more codes to add to frame and stuff

}
public int getUserType(){
 return usertype;
 }
}

When I call the getUserType method, it always returns 0. i've checked if the usertype is assigned any value within the ActionPerformed method and it does. what am i doing wrong here?

thanks in advance