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

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

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

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

In your query change ccc = '%egasg%'" to ccc LIKE '%egasg%'" . Other than that I can't tell what could be wrong with your query.

darkagn 315 Veteran Poster Featured Poster

You can do this:

g.scale = 1;
<?php
$resultCount = mysql_query("SELECT COUNT(*) FROM aa where bbb='1' AND ccc = '%egasg%'") or die(mysql_error());
$count= mysql_result($resultCount,0,0);
?>
g.addRow(<?php echo $count; ?>,3,4,1);
g.title = "haha";
darkagn 315 Veteran Poster Featured Poster

The problem with your method is that the size of your array doesn't change. I would do this in your remove method:
1. create an array of size (original array size -1)
2. go through the original array one at a time.
3. If the index doesn't equal the index of the item being removed, add it to the new array.
4. return the new array.

There are probably more efficient solutions, but that will get the job done.

darkagn 315 Veteran Poster Featured Poster

Try ordering your sub-query by review_date desc. This will then return the last row first and should be picked up by your outer query.

darkagn 315 Veteran Poster Featured Poster

This link has a good explanation of primitives and literals. Let us know if you still have questions after reading this page.

darkagn 315 Veteran Poster Featured Poster

You have a - where there should be an =.

CREATE TRIGGER before_insert_ddsw BEFORE INSERT ON `ddsw`
      FOR EACH ROW SET products.count = products.count +1;
darkagn 315 Veteran Poster Featured Poster

You could try the DISTINCT key word, but I'm not sure if it will help because you are selecting the columns pros and cons which will undoubtedly not be unique.

SELECT DISTINCT
      p.product,
      r.pros,
      r.cons,
      a.AVG,
      a.Latest
      FROM product_tbl AS p
      JOIN (
      SELECT
      product, AVG((price+quality+features)/3) AS AVG,
      MAX(review_date) AS Latest
      FROM review_tbl
      GROUP BY product
      ) AS a ON p.id=a.product
      JOIN review_tbl AS r ON p.id=r.product
      ORDER BY a.AVG DESC;
darkagn 315 Veteran Poster Featured Poster

How should i read a nested for loop? Like would this run essentially 30 times? Does it basically say run the inside loop 10 times? So then does it basically run once, go into the nested loop, run 3 times, then go back into the outer loop, then back into the nested loop 3 times?

Yes, the inner code will be run 30 times. Basically, the outer loop is run 10 times, and each time the outer loop is run the inner loop is run 3 times, (plus the output line is run once each time the outer loop is run).

And I'v read a few definitions and my lecturer has failed what a 'literal' is effectivley. So can i ask, what are they?

A literal is not a terminology I am immediately familiar with, what is the context?

darkagn 315 Veteran Poster Featured Poster

Ok the trick is to decide when the variable is incremented. The pre-increment (++i) occurs before the variable is used in the current statement, so in the final output the increment happens before the output. The opposite is true for the post-increment (i++), here the increment occurs after the variable is used in the current statement.

So, the first output only outputs the value of i. That one's easy. The second one outputs the value of i and then increments it (i++) and the final output statement occurs after i is incremented again (++i). The value of i after the code is complete is a trick question, it wouldn't matter the order of the increments, the value would be -7 either way.

I hope this illustrates to you a bit better how increment works. Try this one for more practice:

int a = 0;
System.out.println(a);
a++;
System.out.println(a++);
a++;
System.out.println(++a);
System.out.println(a++);
System.out.println(a);

Or this slightly harder one involving methods:

public static int squared(int a)
{
  return a * a;
}

int b = 7;
int c = squared(b++);
int d = squared(++b);
int e = squared(b);
System.out.println(b);
System.out.println(d);
System.out.println(e);
System.out.println(f);
darkagn 315 Veteran Poster Featured Poster

The problem here is that your pros and cons, there can be one of each for each and every record, and because they are text they will rarely be the same as another review.

I would do this in two queries, the first returning the average rating and latest review date, the second returning the list of pros and cons, and then deal with the entire set of data as you need.

darkagn 315 Veteran Poster Featured Poster

Well for starters, the code will output three values of i. What are those values at the time that the code outputs?

Sorry about the "$i", that is PHP syntax. It should be:

int i = 17;
      ++i;
      System.out.println(i);
      i = -7;
      i--;
      i--;
      System.out.println(i++);
      System.out.println(++i);

EDIT: Also, what is the value of i after the code is run?

darkagn 315 Veteran Poster Featured Poster

Also the " ++i " thing confuses me, it means that it is iterated beforehand , is that right ? So what kind of questions might involve that?

Can you answer the following common exam question:

What is the output of the following code snippet?

$i = 17;
++$i;
System.out.println($i);
$i = -7;
$i--;
$i--;
System.out.println($i++);
System.out.println(++$i);

EDIT: Here is a link to Google's first site when I typed in "Java exam questions" into the search engine. There were many, many more.

darkagn 315 Veteran Poster Featured Poster

The AVG function will be valuable to you. Basically, you are after an average of the average of your three rating values, so your query will look something like this:

select product_id, avg((price + quality + features)/3) as average_rating from review_tbl group by product_id

You can join with the other table as necessary, or limit your result set to a list of products etc. Have a fiddle with that query and see what you can come up with.

darkagn 315 Veteran Poster Featured Poster

The best text book I used in my Mathematics and CS degree was "Linear Algebra and its Applications" by David C Lay, Published by Addison-Wesley. We used it in three of the five mathematics courses I did (including Discrete Math), and can thoroughly recommend it. I hadn't studied anything for 10 years before I decided to go back to university, so that is probably a pretty good advertisement for this text!

darkagn 315 Veteran Poster Featured Poster

You can't use the == operator on a string comparison in java. You need to call the equals method like so:

if(input.equals("sixty"))
darkagn 315 Veteran Poster Featured Poster

Your if-statement has too many else's. An if-statement in PHP looks like this:

if(boolean condition 1)
{
  // do something
}
else if(boolean condition 2)
{
  // do something else
}
...
else if(boolean condition X)
{
  // do something else
}
else
{
  // if we get here then ALL previous conditions have evaluated to false
  // so there can only ever be one "else" but as many "else if" statements as you need
}

$airdate is ok because when you have grabbed it from the database you have passed it through a call to strtotime to change it to a timestamp.

EDIT: whitestream6, you are very close. Your problem lies not in your calls to date() but in how you are assessing when to use which date format.

darkagn 315 Veteran Poster Featured Poster

Hi JRM,

Sorry for the swings and round abouts, I was trying to explain what was happening without just handing the answer over so that whitestream6 could learn from what was being done. strftime is indeed another approach, but I started down the date() path and didn't want to confuse whitestream6 further. But you do make good points, thanks for the contribution :)

darkagn 315 Veteran Poster Featured Poster

When deleteing from multiple tables, you need to specify what is being deleted. There are two available syntaxes:

DELETE table1, table2 
FROM table1 INNER JOIN table2 ON table1.id = table2.id 
WHERE table1.id = 1

or:

DELETE FROM table1, table2 
USING table1 INNER JOIN table2
WHERE table1.id=table2.id AND table1.id = 1

Hope this helps.

darkagn 315 Veteran Poster Featured Poster

Ok, I think you've got yourself confused with all the variables.
When I gave you this code:

$airdate = strtotime($r['airdate']);
$now = strtotime("NOW");
$currentYear = date("Y", $now);
$yearOfDateFromDatabase = date("Y", $airdate);
if($yearOfDateFromDatabase == $currentYear)

this is what I was doing:
-- get the timestamp of the database record ($airdate)
-- get the current timestamp ($now)
-- calculate the current year ($currentYear)
-- determine the year of the database record ($yearOfDateFromDatabase)
-- compare the current year to the year of the database record

You need to repeat this algorithm for the current day. Here is how I would find the current day:

$currentDay = date("d m", $now); // $now is already defined as the current timestamp

This will make $currentDay the following string for today's date (in Australia anyway): "31 12".
So then you will need to use $airdate to find the day of the database record and compare it to $currentDay.

As an aside, the date 1st January, 1970 at midnight is known as the Unix Epoch. PHP Timestamps are the number of seconds since then, so if you see that date in your output it generally means that your date function has been called with a very low timestamp (the second parameter in the call).

darkagn 315 Veteran Poster Featured Poster

I'm no expert on bat files, but I would suggest changing the line that reads: java -Xmx500M -cp .;./classes/; server to: java -Xmx500M -cp .;./classes/src/; server and see if that fixes your problem.

darkagn 315 Veteran Poster Featured Poster

Simple example:

static int MAX_TESTS = 5;
int test = 0;
boolean result = true;
int something = 6;
while(test < MAX_TESTS && result)
{
  result = (something > 7);
  test++;
}

EDIT: Basically, the while loop takes a boolean condition. This can be the result of a single boolean method or evaluation, or multiple boolean results and'ed or or'ed together (or any other boolean arithmetic).

darkagn 315 Veteran Poster Featured Poster

My suggestion would be to read the documentation of the date function, as I have said before in this thread (twice). Your calls to date do not make sense and I suspect that this is the problem. For example:

$currentDay = date("Y", $now);

This will give the variable $currentDay the value "2009". Is this really what you want? If so the name of the variable does not make sense to me.

Also, please stop PM'ing me, I will look at the thread when I get time.

darkagn 315 Veteran Poster Featured Poster
$currentDayFormatted = date($currentDay, $currentTime);

should be:

$currentDayFormatted = date(<whatever date format you meant>, strtotime($currentTime));

EDIT: In future, please do not say "using Crimson Editor, so the line XX referred to will vary between editors", instead just tell me which line is the line that the error refers to.

darkagn 315 Veteran Poster Featured Poster

Your algorithm should be:
- is it in the current year?
- NO - DateFormat = F jS, Y - g:ia
- YES
-- Is it on the current day?
-- NO - DateFormat = F jS - g:ia
-- YES - DateFormat = g:ia

EDIT: I have already shown you how to find the current year, finding the current day is the same except that you need day and month in your format of the current date.

darkagn 315 Veteran Poster Featured Poster

You have one too many "else" lines in your if-statement. I would not have split airdate into separate date and time fields, what is your thinking there?

darkagn 315 Veteran Poster Featured Poster

Again, use the date() function on $airdate and $now to work out the current day and month, like we did with the year but using different date formats rather than "Y" as the comparison.

EDIT: Also, your lines:

$currentYear = date("Y", $airdate);
$yearOfDateFromDatabase = date("Y");

should be:

$currentYear = date("Y", $now);
$yearOfDateFromDatabase = date("Y", $airdate);
darkagn 315 Veteran Poster Featured Poster

Sorry, you should use:

$airdate = strtotime($r['airdate']);
$now = strtotime("NOW");

and

$airdateFormatted = date($dateFormat, $airdate);

Which line gives the error that you mentioned?

darkagn 315 Veteran Poster Featured Poster

Combine it with the code I already gave you. The only difference between the code you have there and my code is the date format. Read up on the date function (see the link in my first post in this thread) and have a play around with the date format.

darkagn 315 Veteran Poster Featured Poster

Make sure your MySQL column names are correctly spelt, remember that it is case sensitive so "programme" is not the same as "PROGRAMME" or "Programme". I would double check these first, if that doesn't work try a print_r($r) at the top of your loop to check whether the row is correct.

darkagn 315 Veteran Poster Featured Poster

Ok, instead of:

$airdate = $r["airdate"];
// ...
echo "$airdate...";

I would do something like this:

$airdate = $r["airdate"];
$now = strtotime("NOW"); // timestamp of current date/time
$currentYear = date("Y", $now); // format of "Y" gives four digit year ie 2009 not 09
$yearOfDateFromDatabase = date("Y", $airdate); // the year of the record
if($yearOfDateFromDatabase == $currentYear)
  $dateFormat = "d F"; // dateFormat = 12 December
else
  $dateFormat = "d F Y"; // dateFormat = 01 January 2010
// now use $dateFormat when displaying the date!
$airdateFormatted = date($dateFormat, strtotime($airdate));
// ...
echo "$airdateFormatted...";

EDIT: Personally I would put the bulk of the above code into a function but that's up to you.

darkagn 315 Veteran Poster Featured Poster

almostbob makes some good points but I am a bit confused by some of what they have said. They say that they store their timestamp in a SMALLINT field, but a smallint only has a range from -32768 to 32767 which is not big enough to store a 10 digit number. You would need a minimum size of INT to be able to store such a timestamp, and in terms of size this equates to a 4-byte field, the same as a TIMESTAMP or DATE datatype.

Certainly size of your fields should be a factor when designing your database, however this should not be at the expense of ease of use. Sorting of a DATE field will in fact put November before December as it has the format yyyy-mm-dd (ie 2009-12-21 for today). A DATETIME field (which is what the OP was using I believe) acts similarly but is 8 bytes in size due to the fact that it stores the time data as well as the date.

The OP is questioning how to output the DATETIME field (as opposed to a VARCHAR field) in the format that they require. Using a TIMESTAMP still requires a call to date() for output, while a DATETIME can be output in MySQL format immediately or using the date() and strtotime() functions for a different format. However a DATETIME has the added bonus of being a discernable time for a database administrator running a query directly on the table whereas a TIMESTAMP …

darkagn 315 Veteran Poster Featured Poster

I would do this all in PHP code rather than trying to mix with PHPMyAdmin. For example,

// assumes that you have connected successfully to your database using mysql_connect and mysql_select_db
$result = mysql_query("select DATE_COLUMN from THE_TABLE"); // runs a query in your database
if($result)
{
   $row = mysql_fetch_assoc($result); // gets the first result set row from the database for the query
   $databaseDate = $row["DATE_COLUMN"]; // that is, reference the column name of your table
   $formattedDate = date("Y-m-d G:i:s", strtotime($databaseDate)); // this puts the date into the format "yyyy-mm-dd h24:mm:ss"
}

Have a fiddle with my example and see what you can come up with. If you are still having problems, maybe post some of your code so we can see what you are trying to do a bit better?

darkagn 315 Veteran Poster Featured Poster

I would suggest reading up on the following functions in the PHP documentation as they will come in handy when dealing with dates:
date
strtotime
strftime

For example, to find the current year, use the following code:

$now = strtotime("NOW"); // timestamp of current date/time
$currentYear = date("Y", $now); // format of "Y" gives four digit year ie 2009 not 09
if($yearOfDateFromDatabase == $currentYear)
  $dateFormat = "d F"; // dateFormat = 12 December
else
  $dateFormat = "d F Y"; // dateFormat = 12 December 2009
// now use $dateFormat when displaying the date!

Hope this gives you some ideas.

darkagn 315 Veteran Poster Featured Poster

Where is $fullurl set? Also, $b[jobid] should be $b["jobid"] or $b[$jobid] depending on what you meant.

darkagn 315 Veteran Poster Featured Poster

Instead of:

System.out.println("join method test = " + join('a', 'b', 'c'));

you want to call join like so:

// build a char array containing the three characters you tried
char[] chars = new char[3];
chars[0] = 'a';
chars[1] = 'b';
chars[2] = 'c';
// pass the array into the call to join method
String result = join(chars);
// print out the result
System.out.println("join method test = " + result);
darkagn 315 Veteran Poster Featured Poster

You type java Hi , there is no need to specify the ".class" to run your program. Also, you will need a main method in that class to run the program.

darkagn 315 Veteran Poster Featured Poster

Not sure if this is your problem, but I think you may need a <body> tag between your <html> and <table> tags.

darkagn 315 Veteran Poster Featured Poster

I need to make ten selections. One of all the datetimes in the last 24 hours, the next one from 24 hours to 48 hours, and on back in 24 hour blocks for the last ten days. I've tried various approaches to this, but this is what I currently have:

select title, app_id, count(*) as cnt from app_instances where time between now() -1 day and now()-2 day group by title order by cnt desc

The best way I can think of is to run these queries inside a for loop, substituting out the numbers for incremental variables in PHP to result in 10 seperate selections. Does anyone know the correct syntax for this or maybe have a better way?

In PHP the strtotime and date functions might be useful to you. You can go:

for($i=0; $i<10; $i++)
{
  $startDateTime = date("Y-m-d H:i:s", strtotime("-$i days"));
  $endDateTime = date("Y-m-d H:i:s", strtotime("-{$i+1} days"));
  $query = "select title, app_id, count(*) as cnt from app_instances where time between $startDateTime and $endDateTime group by title order by cnt desc";
}

That may require some tweaking to get it spot on, it's just what I came up with on the spot.

darkagn 315 Veteran Poster Featured Poster

You can't use a switch statement like the way you are attempting. Try changing those switch statements to if-else statements and you should be fine.

darkagn 315 Veteran Poster Featured Poster

The line:

new Cite;

means that there needs to be a class called Cite, not a file called Cite.php. Even if there was a Cite class, the code in the wfCite function wouldn't need that line as it doesn't reference the object after that. Remove that line and your code should be fine.

darkagn 315 Veteran Poster Featured Poster

Try adding the following line to your script, anywhere after the line $dir = $documentroot . '/' . $username; but not inside the function:

rmdir_r($dir);

Basically, the code inside the function doesn't execute until the function is called.

aeinstein commented: nice catch and good solve Darkagn +8