darkagn 315 Veteran Poster Featured Poster

Use the parent keyword like so:

class parentClass
{
   // magic call to constructor -> __construct
   function __construct()
   {
      //...
   }
}

class childClass extends parentClass
{
   function __construct()
   {
      parent::__construct();
      // ...
   }
}

OR

class parentClass
{
   function parentClass()
   {
      //...
   }
}

class childClass extends parentClass
{
   function childClass()
   {
      parent::parentClass();
      // ...
   }
}

EDIT: You can add parameters to your constructors and parent calls as needed.

darkagn 315 Veteran Poster Featured Poster

Yes, except that I don't think you need the p in the $row array. The one query should replace all of the queries you previously had, and to get the colour_id (for example) you just go:

while ( $row = mysql_fetch_array($colour_size_lookup) ) {
   $colour_id = $row['colour_id'];
   // ...
}
darkagn 315 Veteran Poster Featured Poster

I would do one query with two joins rather than the three queries you currently have. This allows you to sort on any column from any of the three tables as needed. Something like this would work:

-- select all appropriate columns from the three tables
select p.id, p.product_id, p.colour_id, p.size_id, p.quantity, c.colour_name, s.size_name
-- from the main table
from product_size_colour_lookup p
-- joined to another table on its id
inner join colours c on p.colour_id = c.id
-- and joined to another table on its id
inner join sizes s on p.size_id = s.id
-- now set the sorting however you want
order by c.colour_name asc, s.size_name asc

You may need to modify the query to suit your needs, but my comments should explain what I have done. Please re-post if I have confused you.

Benjip commented: Fantastic, thanks for the help! +1
darkagn 315 Veteran Poster Featured Poster

Looks to me like you are violating your primary key when you try to insert a second record. Make sure that you assign a new PK each time you insert into your Rooms table.

darkagn 315 Veteran Poster Featured Poster

Hi gurinder16 and welcome to DaniWeb :)

Looks to me like you are missing one or more commas in the values section of your query. Count your columns, then count the items you are inserting - these need to be equal as your error message implies.

darkagn 315 Veteran Poster Featured Poster

Hi jeffm2008 and welcome to DaniWeb :)

You need a comma after your last column name and before the words PRIMARY KEY. Like so:

attachments text, PRIMARY KEY ( id )
darkagn 315 Veteran Poster Featured Poster

stardustmeri,

Read through your lecture notes, check out that tutorial i posted a link to, have a try at writing some code, if you get stuck post some questions in the Java forum and there will be people there who can help you out. Try not to beat yourself up about it, learning is a step by step process, and JDBC is (semi)-advanced Java. I would have thought that this would definatley not be a first assignment in a beginner's Java course.

darkagn 315 Veteran Poster Featured Poster

I'm no C++ guru, but I'm pretty sure the shift operator works the same as in Java. Basically a left shift of 1 is like multiplying by 2 to the power of 1 (ie 2), so a left shift of 8 is like multiplying by 2 to the power of 8 (ie 256 or 1 byte).

What your code is actually doing is converting an array of 1's and 0's to a numeric 32-bit integer (32 bits = 4 bytes). It does this by adding the bytes together. The first byte starts at position 0 in the bit array, so no shift is necessary. The second byte starts at position 256 in the bit array, so we need to left-shift by a power of 8 in order to calculate the numbers that this byte represents. Similarly for the other two bytes...

darkagn 315 Veteran Poster Featured Poster

System.currentTimeMillis() will give you the current time in milliseconds. Call this method before your code does anything else, then again after your code is finished, then find the difference and you have the number of milliseconds that your code ran for.

darkagn 315 Veteran Poster Featured Poster

Would you not mind if you explain this to me further? I am really stuck regarding to this matter. Sorry if it sounds demanding on your part.

Here is how you add containers to your content pane:

Container frontpage = getContentPane();
Container anotherContainer = new Container();
frontpage.add(anotherContainer);

The getContentPane() call gets a reference to the Window's main drawing area (known as the content pane). You were trying to get three references to it (ie all the same object) and then add itself to itself. What I think you actually wanted to do was create another container and add it to the content pane.

Actually, they were supposed in separate classes. But they always open a new window that's why I decided to put them as inner classes. Well, it causes a lot of errors. :(

It causes lots of errors because your syntax is completely wrong. You are trying to write code in a class that executes like a method. If it is supposed to be a separate class, then create another class with methods in it that perform what you are trying to do.

darkagn 315 Veteran Poster Featured Poster

Ok, well JDBC stands for Java DataBase Connectivity, so I'm guessing you need to write your program in java. Check out this tutorial, if you get stuck on the concepts please post your attempt and where you are struggling. Sorry but we aren't allowed to just do your assignment for you.

darkagn 315 Veteran Poster Featured Poster

The LIKE statement might prove useful.

SELECT * FROM Discriptions
WHERE Description LIKE '%paint%' or Description LIKE '%red%'

The above statement will find any description where one or both of the words paint or red appear anywhere in the string. The % is a wildcard character that represents any set of characters, another is the _ (underscore) character that is used to indicate any single character.

Example:

SELECT * FROM Discriptions
WHERE Description LIKE 'r_d'

will return any three character string it finds with r as the first character and d as the third character.

These are just suggestions, not sure if it will help but was the first thing I thought of when I read your post. Good luck :)

darkagn 315 Veteran Poster Featured Poster

Hi ismael ahm@d and welcome to DaniWeb :)

You probably don't need to store the balance in the database as you can calculate this very easily on the fly in PHP, but if you really want to you just do a simple update statement on the database. Something like this:

UPDATE balances_table
SET balance = credit - debit

To calculate the sum of your data, you use a SUM() query, like so:

SELECT SUM(debit) as debits FROM balances_table
darkagn 315 Veteran Poster Featured Poster
Container main = getContentPane();
Container frontpage = getContentPane();
Container node = getContentPane();

...

frontpage.add(main);
frontpage.add(node);

Here you create 3 references to the content pane of your JFrame, then try to add 2 of those references to the third.

I would get rid of all references to main and node variables, and just use frontpage as your reference to the content pane. If you want to add more containers, then create new instances of a Container subclass and add them to frontpage.

EDIT: Also I don't think that mainPage and newProfile should be inner classes, they look like methods to me, but that's a different issue I suppose...

darkagn 315 Veteran Poster Featured Poster

Make sure that line 7 (and all lines for that matter) in your csv don't have more than 19 commas. That will give you 20 values in a csv file. This line in a csv file:

1,,2,,3

actually has 5 values, it's just that 2 of the values are null/blank.

darkagn 315 Veteran Poster Featured Poster

Your problem is with this line:

for(x=0;x<sample.length();x++)

If you enter something that is less than 52 characters (because sample.length() = 52 in your code), then when you do the enter.charAt for something past the end of what has been entered, you will receive an error. You need to change the condition of the for-loop so that you don't go past the end of what has been entered, and you also don't exceed the length of sample (which you already have checked for).

HTH,
darkagn.

darkagn 315 Veteran Poster Featured Poster

You have a comma after the '$b15' entry that shouldn't be there.

darkagn 315 Veteran Poster Featured Poster

I would just add a tinyint field to your orders table that represents the status of the order. 0 = ordered, 1 = cancelled, 2 = shipped etc. Then when you want to view your outstanding orders, just filter according to the status of the order. This implementation allows you to keep a "paper trail" of every order, regardless of whether it was actually carried out.

darkagn 315 Veteran Poster Featured Poster

Selecting data across multiple tables is done with a JOIN statement. There are several types of JOIN, the most basic is the INNER JOIN. This allows you to join two tables with a common set of columns. For example, if your main table has an ID field called family_id, and each member of the family is stored in another table that contains the family_id to indicate which family they belong to, then you can do this:

SELECT * FROM families
INNER JOIN family_members
ON families.family_id = family_members.family_id

There are millions of SQL examples on the web that can tell you how to join in other ways. Hope I have helped!

PS Your english is good, I understood what you were after so don't worry about it!

darkagn 315 Veteran Poster Featured Poster

In that case you need to left join in your update query too. Basically the where clause needs to be able to identify the column that you are filtering on. Try a select statement first to select the exact row you want, then adjust it to an update query without changing your joins and where clause and you should have no trouble.

darkagn 315 Veteran Poster Featured Poster

Can you try this code and let us know the result:

$colname_Recordset1 = "-1";
if (isset($_GET['user_name']))
   $colname_Recordset1 = $_GET['user_name'];
$result = mysql_query("SELECT * FROM content WHERE user_name = '$colname_Recordset1' ");
if (!$result)
   echo mysql_error();
else
   print_r(mysql_fetch_assoc($result));
darkagn 315 Veteran Poster Featured Poster

Is the user_name column in your table a number or a varchar? If it is a varchar, you need to surround it with single quotes in your SQL query, like so:

mysql_query("UPDATE content SET counter = counter + 1 WHERE user_name = '$colname_Recordset1' ");
darkagn 315 Veteran Poster Featured Poster

Phoogle is a google maps package for PHP. Here is a link to the systemseven website (developers of Phoogle).

darkagn 315 Veteran Poster Featured Poster

Hi vivobie and welcome to DaniWeb :)

I think that the GeoIP PHP extension library can determine country (as well as lots of other locale information). I have never used it, but here is a link to its documentation.

darkagn 315 Veteran Poster Featured Poster

Hi denny42 and welcome to DaniWeb :)

So is Name the same in each table? ie is it referring to the same thing? If so, you can join the tables on that field like so:

select t1.Name, t1.amount, t2.nominal
from Table1 t1
left outer join Table2 t2 -- left outer join will return all results even if there is no entry in table2 for the corresponding record in table1
on t1.Name = t2.Name -- specifies the column(s) to join on

The above query gives you the Name, amount and nominal columns from your two tables.

Now the SUM() function is used to sum a set of values, and you can use a GROUP BY clause to tell how to sum the values. So the following query will sum the amount column from table 1 for each Name in table 1:

select Name, SUM(amount)
from Table1
group by Name

Ok, there's two pretty big clues as to what you need to do, have a go at combining what I have said and post back if you get stuck.

darkagn 315 Veteran Poster Featured Poster

Hi jpavao and welcome to DaniWeb :)

It won't actually contain itself, it will contain another instance of the same class. For example, if it were a JPanel, your code would look something like this:

JPanel parentPanel = new JPanel();
JPanel childPanel = new JPanel();
parentPanel.add(childPanel); // --> NOT parentPanel.add(parentPanel);
BestJewSinceJC commented: good helpful attitude :) +4
darkagn 315 Veteran Poster Featured Poster

Here is a good tutorial on what SQL injection is, how it can be used maliciously and measures that can be taken to prevent such attacks.

darkagn 315 Veteran Poster Featured Poster

Yeah, i was in favour of that "Up to" rep system back when Dave first suggested it, i'm surprised there hasn't been more talk on the subject. It sounds like a great idea.

Not to mention that it removes the double-up of what is really two functions serving a single purpose.

darkagn 315 Veteran Poster Featured Poster

Sorry you may have missed my edit, you need to change where you are declaring your methods (that is, not inside your main method).

darkagn 315 Veteran Poster Featured Poster

Hi ronyyy,

DaniWeb has a golden rule that we only give homework help to those who have shown some effort first. Have you attempted the problem yet? If so, please post your code snippet and describe what problems you are having, otherwise what ideas have you come up with for your algorithm?

darkagn 315 Veteran Poster Featured Poster

Ah ok, remove the semicolon. In java you declare a method like so:

public void buyOneDozen(double pricePerdozen)
{
   // method functionality goes here
}

You will similarly need to remove the other semicolons after your other method declarations.

EDIT: Also, you are declaring those methods inside your main method. I don't know that this is what you want to do...

darkagn 315 Veteran Poster Featured Poster
label2 = new JLabel ("Think",pic4, SwingConstants.RIGHT);

I think you should be referencing pic2 here instead of pic4?

darkagn 315 Veteran Poster Featured Poster

Please use code tags. What line is the error reported on?

I suspect the error has to do with the fact that you name your member variable numEggs but then refer to it as numOfEggs in the rest of your code.

darkagn 315 Veteran Poster Featured Poster

Ah, sorry I misunderstood. So your query will require a join to the scientistvisits table, joining on farmerid, but only where the farmer is male (for example). I will use a left outer join here because if the farmers have had no visits, we want to return a result of 0 rather than simply missing them (as an inner join would). So the syntax looks like this:

select count(*) from farmers f
left outer join scientistvisits v
on f.id = v.farmerid
where f.sex = 'male'
group by f.id

EDIT: The group by clause here will group the results by the farmer, so this way you can see the number of visits for each farmer. If you remove the group by clause, the result will be a single row, giving the total number of visits to male farmers, in which case an inner join would be more efficient.

darkagn 315 Veteran Poster Featured Poster

Why not do each in a separate query? For example, to find the number of male farmers:

select count(*) from farmers where sex = 'male'

All the other queries will be similar, just substitute farmers for whichever table you are querying and change your where clause appropriately.

darkagn 315 Veteran Poster Featured Poster

But according to this, 599 / 100 should return 5.99 because they are not evenly divisible. I've never had an issue with that not working...

No, 599 is an integer, 100 is an integer, so the result of the division is an integer. 599/100=5, 599%100=99, 599/100.0=5.99.

Another thought, if this does prove to be an issue. You could multiply by 0.01 instead of dividing by 100. It's the same net effect, but it should guarantee a float value.

Yes that's correct, as is dividing by 100.0, or changing 599 to 599.0.

darkagn 315 Veteran Poster Featured Poster

The System.out.print function takes a String parameter, so you should be able to perform assertions on the string that you are passing to it.

darkagn 315 Veteran Poster Featured Poster

Your $x is a string, you should really have it be an integer. Then, all you would have to do is divide by 100.

If you need a string for some reason, you could try to use intval() to extract an integer value from the string. You still would have to divide by 100 to shift the decimal though.

Two things: firstly, php is loosely typed, so if a string happens to be an integer or floating point number you can use it as one, and secondly, if you simply divide 599 by 100 I think you will be surprised by the result (5 not 5.99!)

darkagn 315 Veteran Poster Featured Poster

I understand the reasons of anonymity, but for me I would like a reason as to why my post has been up/down voted. I don't understand why someone has decided to down-vote a post that I think was helpful without blurting out an answer, but up-vote another post in the same thread that is grammatically incorrect and uses IM-speak and fails to meet the OP's questions. Of course, these votes could have been done by two completely different users, but I think you can see what I am getting at...

Overall I don't really take much notice of the up/down vote system, but I would like to learn to be more helpful in the posts I make, so prompting people to give a reason for their votes could be worthwhile and might add to the feature.

Sorry, I know that this feature has been debated several times already and I hate to beat a dead horse...

darkagn 315 Veteran Poster Featured Poster

Personally I prefer the Reputation as a measure of one's helpfulness/popularity on DaniWeb, and truthfully I haven't paid much attention since the introduction of the Up/Down Voting system. But lately one thing is starting to bug me about it - if someone up/down votes a post, it is completely anonimous and no reason need be given. I would prefer someone tell me why they like/dislike one of my posts so that I can either debate their response or learn from their point of view. Honestly, can anyone put forward a reason as to why such a "feature" was implemented when we already had the perfectly acceptable reputation feature? I know this has kind of been done to death, but I am still yet to be convinced of its purpose or value.

darkagn 315 Veteran Poster Featured Poster

Have you tried adding the brickboard to the panelbg rather than to the window?

darkagn 315 Veteran Poster Featured Poster

Hi scmsimplybest and welcome to DaniWeb :)

Not sure exactly what you are asking, but if you want the field to not be shown to the user, use a hidden input type rather than a select. Keep track of the variable in the $_GET array and pass by parameter to your url.

darkagn 315 Veteran Poster Featured Poster

Ok what I would do is store the create_date = now - starting_age. Then I would use the above algorithm to calculate the age on the fly.
Example:
Create a record now with a start_age of 5 days. create_date of the record is now - 5 days = 4 Feb 2010 (in Australia) - 5 days = 30 Jan 2010.
Tomorrow the age is current day - create_date = 5 Feb 2010 - 30 Jan 2010 = 6 days. You don't need to store this age in the database and constantly update it, just calculate it when the record is read.

That's what I would do anyway. Personally I think it is easier to implement, uses less storage and creates less load on the database.

darkagn 315 Veteran Poster Featured Poster
$sql2="UPDATE table SET present_age = '$presentage' WHERE batch_no='$batch'";
$query2=mysql_query($sql2);

I don't understand why you are doing this. You shhouldn't need to store the age in the database, just calculate it when you are displaying the age.

However if you REALLY want to do this, then change the line:

$presentage=$presentage+$fullDays;

to

$presentage=$fullDays;

EDIT: Have I mentioned that this is very bad database design?

darkagn 315 Veteran Poster Featured Poster

What's your java code? Certainly a decimal would work with a value of 23.50 (that's what a decimal is) and numeric could work if it had appropriate precision values.

darkagn 315 Veteran Poster Featured Poster

I have to disagree with tomatocms on this one. There is no need to store the "age_field" in the database. If you had 100000 records in your table there would be 100000 unnecessary fields, expanding the memory used by your database. You can calculate the age of something very easily in code with the algorithm outlined in my previous post.

darkagn 315 Veteran Poster Featured Poster

I would store the create_date in the database in a datetime field. Then you can easily work out the age by grabbing the current time (with the time() function) minus the timestamp of the create_date (using strtotime() function) and dividing by the number of seconds in one day. Integer division in PHP drops any remainder, so this algorithm will give you the number of whole days since the create_date.

darkagn 315 Veteran Poster Featured Poster

The toString method is inherited from a parent class if it isn't overriden in the class that you are calling on. This is true for all classes, since all classes derive from at least the Object class, which contains a toString method. The Object.toString() method prints the name of the class, followed by the @ symbol, followed by the object's hash code, so that is what you are seeing when you print your SomeClass1 object. I suspect that your collectionobject class either contains a toString method or derives from a class that does.

darkagn 315 Veteran Poster Featured Poster

Hi 16pradeepkumar and welcome to DaniWeb :)

Do you need to specifically export to xls file format? The reason I ask is that it is not a trivial task to do this, whereas export to cvs is simple and you can open a cvs file in Microsoft Excel.

darkagn 315 Veteran Poster Featured Poster

MySQL includes a LIMIT function which you can use like so:

select * from my_table
order by my_key asc
limit (0,1)

This will display one record starting at index 0 (ie the first record returned). If you said LIMIT(10,5) it would display five records starting at index 10 (items 11-15).

So what you could do is keep a track of which record they are up to, and when the press the button increment the first parameter in your LIMIT clause.