darkagn 315 Veteran Poster Featured Poster

Hi cvarcher / Rick and welcome to DaniWeb :)

All of your code looks ok to me, so I am going to ask a few obvious questions:

Firstly, is there a record in the jos_membership table with the supplied ID? Is ID the entire Primary Key of the table? - if so, you don't need LIMIT 1 at the end of your table. Are you refreshing the table data in phpMyAdmin? Is $result true?

darkagn 315 Veteran Poster Featured Poster

It needs to match the column name for the ID of the comment being replied to.

darkagn 315 Veteran Poster Featured Poster

Ok, I can see you are trying, I will show you what I would do for your add methods, then you can write the minus methods.

public static Money add(Money m1, Money m2)
{
  int dollars1 = m1.getDollars();
  int dollars2 = m2.getDollars();
  int cents1 = m1.getCents();
  int cents2 = m2.getCents();
  // now we have all of the info we need to add the two together
  int sumDollars = dollars1 + dollars2;
  int sumCents = cents1 + cents2;
  // now we need to check if we have too many cents
  if( sumCents > 100 )
  {
    sumDollars = sumDollars +1;
    sumCents = sumCents - 100;
  }

  Money output = new Money( sumDollars, sumCents );
  return output;
}

public void add(Money m)
{
  int dollars1 = this.getDollars();
  int dollars2 = m.getDollars();
  int cents1 = this.getCents();
  int cents2 = m.getCents();
  // now we have all our info
  int sumDollars = dollars1 + dollars2;
  int sumCents = cents1 + cents2;
  // again, check to see if we have too many cents
  if( sumCents > 100 )
  {
    sumDollars = sumDollars + 1;
    sumCents = sumCents - 100;
  }
  // now the purpose of this method is to update the caller's values of dollars and cents with new values
  this.setDollars( sumDollars );
  this.setCents( sumCents );
}

Have a go at the minus methods and let me know if you don't understand what I have done.

darkagn 315 Veteran Poster Featured Poster

That looks ok, except that the add2 and minus2 methods should not return anything (ie void instead of int). Yes, you need to put something in your add and minus methods, but you need to figure out what. I wanted to give you a hint, and let you actually write the method yourself. I would change your toString method too:

public String toString() {
  return ("$" + getDollars() + "." + getCents() );
}

Now when you print your Money object it will be in the form of $5.30 for example. You may need to change it for situations where cents < 10 so that it has a leading 0.

darkagn 315 Veteran Poster Featured Poster

No, it is your constructor with two parameters. You call it by saying new.

EDIT: Your constructor methods look ok, by the way. You just need to change your add and minus methods.

darkagn 315 Veteran Poster Featured Poster
echo "<form method=\"post\" action=\"./index.php?act=test&id=".$row['id']."&reply_id=".$row['id']."\">\n";

I believe your problem lies here. You are in effect setting $_GET to $_GET, which in turn sets $reply_id to $tid when the page is refreshed after the submit of the form.

darkagn 315 Veteran Poster Featured Poster

Please use code tags when posting your code.

You have missed the point of my last post. You don't pass in two ints to your static add method, you pass in two objects of type Money, each of whom contain two int fields that need to be added together and returned as a Money object. The test for this would be like so:

Money m1 = new Money(5,30); // this one = $5.30
Money m2 = new Money(6,90); // this one = $6.90
Money m3 = Money.add(m1,m2); // m3 should = $12.20

For the non-static method, you need to create two Money objects and call the add method to add one to the other. The test would look like this:

Money m4 = new Money(5,30); // m4 = $5.30
Money m5 = new Money(6,90); // m5 = $6.90
m4.add(m5); // now m4 should = $12.20
darkagn 315 Veteran Poster Featured Poster

Hint: Your method signature for the add method should look like this:

public static Money add(Money m3, Money m4)

The method should add the dollars and cents of each Money object and return another Money object. You will need to take into account what happens when you add 90 cents to 50 cents to the dollars and cents of the returned object.

A similar approach is required for your static minus method.

EDIT:
For the non-static methods, the following method signature is what is required:

public void add(Money m)

This method should add the dollars and cents values of m to the caller's dollars and cents. Similar for minus.

Have a go, repost if you need further help :)

darkagn 315 Veteran Poster Featured Poster

Hard to say what is happening in the mss function without seeing the code, however I notice that you use the mss function twice with different parameters:

$msg = mss($_POST['reply']);
$tid = mss($_GET['id']);

Does it return two different things based on what is passed in?

darkagn 315 Veteran Poster Featured Poster

Does mss give you the right id according to the data that you have in the database? That is, is it the mss function or the data in the database that is wrong?

darkagn 315 Veteran Poster Featured Poster

mss function should get the 'ID' of the topic from forum_topics!!!!

I don't think it is returning the right value here. Try echoing $tid just before you run your sql, or better yet, echo the sql to the screen and check that it has the right variables.

darkagn 315 Veteran Poster Featured Poster

What does the mss function do? I think that it is returning nothing whereas it should return the id of the topic...

darkagn 315 Veteran Poster Featured Poster

Sorry I haven't seen a query is empty error before - maybe start a new thread to ask someone else?

The $reply_id is just the ID of the message being replied to. I thought you said before that you were able to retrieve this when the reply button was pressed?

darkagn 315 Veteran Poster Featured Poster

Hi zammari10 and welcome to DaniWeb :)

Your issue is a different one to this thread. I suggest you start a new topic so that more people will read your question and hopefully someone will have an answer for you.

darkagn 315 Veteran Poster Featured Poster
$sql4 = "INSERT INTO forum_replies (tid,uid,message,date,time,reply_id,pid) VALUES($tid,$_SESSION['uid'],'".$msg."','".$date."','".$time."',$reply_id,$pid)";

You need to work out how to find $pid in your php code...

darkagn 315 Veteran Poster Featured Poster

Ah, ok, you need to move your calcarea method inside the class.

EDIT: No wait, it is inside the class. This exception is usually raised when you miss closing a bracket or brace or miss a semi-colon. Double check your code to make sure that hasn't happened. Also "Double" should be "double" in the calcarea signature.

darkagn 315 Veteran Poster Featured Poster

Which line is line 36 of your file?

darkagn 315 Veteran Poster Featured Poster

I assume you want $nowdate to be a string. String concatenation in PHP uses a period character to join strings. This **should** work:

$nowdate = date('Y') . "-" . (date('Y') + 1);
PinoyDev commented: useful +1
darkagn 315 Veteran Poster Featured Poster

You need to remember the topic id of the post being replied to as well as its ID. The new reply will have a new ID, the same topic id as the post it replied to and a parent id equal to the ID of the post being replied to.

darkagn 315 Veteran Poster Featured Poster

Have you made the necessary change to the forum_replies table? That is, have you added a column to store the parent_id? If so, take a look at my earlier reply (#10) which gives you the SQL you need to insert a new record into the database if it is a reply to a reply. The parent_id of the new record is the id of the comment being replied to, which you are saying you can see...

darkagn 315 Veteran Poster Featured Poster

area = (radius * 3.14)^2;

Two things: first, the area of a circle is PI * r^2 not (r * PI)^2. Secondly, the java compiler doesn't recognise the ^. You need to use the Math.pow method to raise something to a power, but in this case it is easier to just multiply PI by radius by radius.

darkagn 315 Veteran Poster Featured Poster

If it's working as you would like, then it is correct :P

Try testing a few situations to make sure though. What happens if you post a no-message response now? Try it in different browsers if possible, especially IE and FF.

I still have concerns about your html, you don't close the form tag and your newlines might behave strangely. But if it's working then cool! :)

darkagn 315 Veteran Poster Featured Poster

Not sure about this one mate.

Possibly, the html code doesn't have a closing </form> tag. Also, I notice that you use \n for a new line in your html, you should use <br> tags instead for cross platform and browser compatability.

Otherwise, I am not too sure. Try printing out your $_POST array and checking that there is an entry for 'reply'. Use the print_r function to do that, like so:

echo "<pre>";
print_r($_POST);
echo "</pre><br>";
darkagn 315 Veteran Poster Featured Poster

Mate, I am going to follow your technique.....as it makes sense.

Now at the moment I have a reply box at the bottom of each thread. which is basically replying directly to the topic instead to the comment.

I have two ideas.....

1. Remove the reply box from the bottom of the page and have a reply button which when clicked on directs to the page to the reply page with the reply box.

2. Now, to reply to a comment have a reply or quote button after each comments

What do you recon how should I do it.......?

Thanks

Yep, that's exactly what I would do. Maybe start with the reply button after each post and worry about the quote button when this is all working. Don't forget that you will need to remember the ID of the post that is being replied to (and later quoted).

(Please see attached.)

How can I adjust my SQL so that when its reply to a reply it will update the parent_id.

Thanks

It's just a matter of adjusting your insert statement so that the parent id is inserted. When the reply button is pressed, you will need to remember the ID of the post being replied to. Let's say it is stored in a variable $pid, then your insert statement becomes:

$sql3 = "INSERT INTO forum_replies (tid,uid,message,date,time,pid) VALUES ($tid,$uid,'$message','$date','$time',$pid)";
darkagn 315 Veteran Poster Featured Poster

Ah ok, sorry I misunderstood your intent. So in order to loop through each product, I would use a CURSOR. Basically a cursor provides a way to loop through objects in a table. Here's a simple example:

-- declare some variables to store the info for each product
DECLARE @ProdID int,
@Description varchar(30),
@Price smallmoney
-- create the cursor
DECLARE ProductCsr CURSOR FOR
  SELECT ProdID, Description, Price FROM Products
-- start the cursor and fetch the first record
OPEN ProductCsr
FETCH NEXT ProductCsr INTO @ProdID, @Description, @Price
-- Note that the order of values in the INTO part must match the order in the SELECT statement of the Cursor
-- loop through each record until we get to the end
WHILE @@FETCH_STATUS = 0
BEGIN
  -- here is where you do whatever you want to the data
  -- for example to update each record with a new price we could
  UPDATE Products SET Price = @Price + 1.50 WHERE ProdID = @ProdID AND Description = @Description
  -- fetch another record
  FETCH NEXT ProductCsr INTO @ProdID, @Description, @Price
END
-- cleanup after yourself
CLOSE ProductCsr
DEALLOCATE ProductCsr

This is a very simple example of how to loop through every record in a table. Cursors can be used for many different things, I think your situation would suit its purpose. Just remember to backup the database beforehand!

darkagn 315 Veteran Poster Featured Poster

This looks to be more of a PHP question than a MySQL question, but I think I can help. I would assign the results to variables in php and then simply add them. Like so:

$w = $row_standings['w'];
$d = $row_standings['d'];
$sum = $w + $d;
echo "$w + $d = $sum";

This can work with multiplication too, just change the + to a *.

Hope this helps,
darkagn :)

darkagn 315 Veteran Poster Featured Poster

So if I replied to the topic, replying to the post with message "hey", ParentID of my post would be 33, yes. But the ID of my post would not be 33, it would be something else. If auto_increment for example, mine would have ID of 34. So after I replied to that post the tables would look like this:

forum_replies
id - tid - uid - message - date - time - edit_time - parent_id
33 10 4 hey 20/03/2009 1237593182 0 NULL
34 10 6 hey yourself 21/03/2009 1237563999 0 33

forum_topics
id - cid - title - uid - date - time - message
10 9 hello 4 21/03/2009 1237593999 hiya

That's how I would do it anyway. There may be a better solution out there...

darkagn 315 Veteran Poster Featured Poster

All I meant by that was that any post, whether it be a reply to an existing post or one that starts a new topic, should be inserted in this table. If it starts a new topic (as opposed to a reply) I would set a ParentID column to null. If it is a reply to a specific post (as opposed to a topic) I would set ParentID to be the ID of the post that was replied to. TopicID would still house the ID of the thread that was replied to, but in this way you can tell which post has been replied to.

I hope this makes sense, but reading back on it I think I have made myself a bit confused. Let me know...

darkagn 315 Veteran Poster Featured Poster

What are the tid and uid columns used for? I think I would have a column for ID of the reply, TopicID for the ID of the thread that it was posted to and a column for ParentID for the ID of the reply that it was posted against. This would mean that every post should be stored in this table, and the first post of a topic would have a NULL ParentID. So instead of forum_replies I would name the table forum_posts.

darkagn 315 Veteran Poster Featured Poster

Hi alexstrong29 and welcome to DaniWeb :)

If the recommended products are also in the products table, what I would do is add four columns to your product table that represent the product ID's of each recommended product for the row. That way your database grows by a lot less than having a separate table that is four times larger than your current products table.

Hope this helps,
darkagn :)

darkagn 315 Veteran Poster Featured Poster

Is your chat window in Java? If so is your GUI written in swing or awt? Perhaps some code to describe how you construct your window would help...

darkagn 315 Veteran Poster Featured Poster

The most basic program requires some form of planning, even if it is just a few notes on some scrap paper. It is always a good habit to plan, you will make fewer mistakes and write more manageable code if you spend time planning first. Personally I never "just jump into coding with just a vague idea of how a program is supposed to run".

darkagn 315 Veteran Poster Featured Poster

What is the type for the field 'creationdate'? Is it a date, datetime, smalldatetime or something else?

darkagn 315 Veteran Poster Featured Poster

Hi again,
The easiest way to avoid duplicates is to limit the select statement according to some criteria. Do you have an ID field in the table that you can use, or some sort of date field to specify when the object was inserted? ID is easiest:

INSERT INTO ServerB.DatabaseName.dbo.Employee B
(SELECT * FROM ServerA.DatabaseName.dbo.Employee A
WHERE B.ID NOT IN (SELECT ID FROM A)

but date can also be done:

INSERT INTO ServerB.DatabaseName.dbo.Employee B
(SELECT * FROM ServerA.DatabaseName.dbo.Employee A
WHERE B.DATE > (SELECT MAX(DATE) FROM A)

Let me know if you don't have such a structure in this table (maybe describe the primary key for me please?)

To backup the database first (which is ALWAYS a good idea btw), in SQL mngmnt studio 2005, right-click the database and select Tasks from the popup menu and select Back Up from the submenu. You need to check the settings in the screen that appears, pretty much the only thing I ever change is the destination. Press the Backup button and watch the magic unfold!

HTH,
d

darkagn 315 Veteran Poster Featured Poster

You don't need quote marks around table or column names. This SQL should work for you:

SELECT * FROM forum_cats WHERE admin < ".$row['admin']."+1
ORDER BY admin ASC
darkagn 315 Veteran Poster Featured Poster

So you will need to join the tables like so:

SELECT resortloc, resortname FROM table1
INNER JOIN table2 ON table1.resortid = table2.resortid
WHERE table1.resortloc = (SELECT MAX(resortloc) FROM table1)

This is of course assuming that resortloc is a numeric value, ie 30 not "30 miles".

darkagn 315 Veteran Poster Featured Poster

Hi Lido98 and welcome to DaniWeb :)

This can be done in SQL Management Studio in a few easy steps:

  • First of all, you need to connect to Server B.
  • Once connected, you need to link Server A to Server B. In SQL Mngmt Studio 2005, this can be done by right-clicking Linked Servers under the Server Objects field and adding the new linked server.
  • Then you need to run a query similar to the one below.
INSERT INTO ServerB.DatabaseName.dbo.Employee
(SELECT * FROM ServerA.DatabaseName.dbo.Employee)

Where ServerA is the server name of Server A, similar for ServerB and DatabaseName is the name of the databases on each server. I should also point out that if the Employee table has an auto increment field and you want to preserve the order of this field, you need to set auto increment off for the ServerB Employee table before you run the insert and reset it to on when you have finished. Let us know if you need to do this and we'll show you how.

Anyway, hope this helps :)
d

darkagn 315 Veteran Poster Featured Poster

Hi keofua and welcome to DaniWeb :)

Can you post the error messages that you are getting please? That might help us to identify the problem.

Regards,
d

darkagn 315 Veteran Poster Featured Poster

I think those methods belong in the Box class itself. For example,

private class Box {
      private double length = 0.0;
      private double width = 0.0;
      private double height = 0.0;

      public Box(double boxlen, double boxwid, double boxhei)
      {
        length = boxlen;
        width = boxwid;
        height = boxhei;
      }

      public void setLength(Double boxlen)
      {
        length = boxlen;
      }

      public double getLength()
      {
        return length;
      }

      public void setWidth(Double boxwid)
      {
        width = boxwid;
      }

      public double getWidth()
      {
        return width;
      }

      public void setHeight(Double boxhei)
      {
        height = boxhei;
      }

      public double getHeight()
      {
        return height;
      }

      public double getVolume()
      {
        return length * height * width;
      }
}

After all, volume, surface area and total edge length are all properties of the Box, not of a Main.

Also notice that I have spelt double with a lower case 'd'. You are not using the class Double, but the primitive double, to store the values of height, width and length.

darkagn 315 Veteran Poster Featured Poster

Assuming the primary key is stored in a PHP variable, $key, then you can build your SQL query using double quotes:

$sql = "SELECT * FROM table1 WHERE ( SELECT COUNT(*) FROM table2 WHERE fbid = $key) > 150";
// run the query by passing $sql to your query handler
darkagn 315 Veteran Poster Featured Poster

You might want to invest in a third party WYSIWYG editor. There are lots out there, Google or another search engine might be a good place to start...

darkagn 315 Veteran Poster Featured Poster

This sounds like sorting an array rather than a queue. As you said, queues work on the FIFO format, so you can't sort a queue since you will lose track of which one should be removed next. Are you sure this is what your task requires?

darkagn 315 Veteran Poster Featured Poster

Hi ilokana and welcome to DaniWeb :)

I'm not sure exactly what you are trying to do here? Do you want to create a drop-down box that when the user selects an option it automatically redirects them to a selected link? Why do you not want a Submit button?

Regards,
darkagn

darkagn 315 Veteran Poster Featured Poster

Really your question has many different answers depending on the individual. Personally I prefer Eclipse, but NetBeans is very popular. I used to use jEdit and I always liked it, but it wasn't a true IDE, just a text editor with a few plugins for java development.

darkagn 315 Veteran Poster Featured Poster

I think StringBuffer might be the other String__ class you were referring to. Both the StringBuilder and StringBuffer class are better at concatenation than the base String class. StringBuilder will out-perform StringBuffer (although both are highly efficient at concatenation) but note that StringBuilder does not guarantee synchronisation, meaning that you should only use it if it is being accessed by a single Thread. Multi-Threaded applications need to use StringBuffer, or control the synchronisation themselves.

darkagn 315 Veteran Poster Featured Poster

The COUNT function will return the number of rows returned by the query which is what I think you are trying to do. The COUNT function requires a column to count as a parameter, so your query will look something like this:

select COUNT(name) as number_sold
from beats
where availability = 'Sold'
and p_staffid = 1;
CodeBoy101 commented: Exactly what I needed. +0
darkagn 315 Veteran Poster Featured Poster

As an aside, if you want to limit people to only use one instance of your class in an application, you can do something like this:

public class myClass {

  private static myClass instance = null;

  private myClass()
  {
    // do something when creating the instance
  }

  public static myClass getInstance()
  {
    if( instance == null )
    {
      instance = new myClass();
    }
    return instance;
  }
}

The Runtime class does something similar in order to limit the number of instances of Runtime objects to one.

darkagn 315 Veteran Poster Featured Poster

You need to use the static getRuntime() method in order to instantiate the Runtime object.

darkagn 315 Veteran Poster Featured Poster

Take a look at the Runtime class. You can use its exec method to run a ping and the resulting Process has methods to allow you to obtain the I/O/E streams. This allows you to interpret the results of your ping, but note that there are differences in the ping implementation in Windows and Linux (not sure about Cisco OS sorry).

Hope this gives you some direction,
darkagn

darkagn 315 Veteran Poster Featured Poster

Should zipCode belong to the Individual class or the IndividualArray class? I think it is a value relating to the Individual, not the list of Individuals.