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

the php file is my problem
it is supposed to delete product and add a replacement for it

What is it doing instead? Do you get any errors?

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

All dates in MySQL are in the format: yyyy-mm-dd. Notice the hyphens and the number of digits ie 4 for the year, 2 for the month and 2 for the day. Today's date would be entered as 2009-12-24 and New Years Day would be entered as 2010-01-01.

That said, if your dob is a single date field, then your query should look something like this:

insert into members3t (securecode, gender, firstname, lastname, dob, age) 
values ('$securecode','$gender','$fname','$lname','$dob','$age')

Notice that the number and order of columns in the insert part of the query must match the number and order of columns in the values part of the query, and all opened brackets must be closed (balanced).

darkagn 315 Veteran Poster Featured Poster

It would be easier if you could combine your ss_datestart and ss_timestart columns into one DATETIME column (and similar for end date and time), but you could do something like this in php:

// all timestamps are in seconds, so define the number of seconds in one hour
define("SECONDS_PER_HOUR", 60*60);
// get the data from the database
$result = mysql_query("select ss_datestart, ss_timestart, ss_dateend, ss_timeend from datetimetable") or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
   // calculate the start timestamp
   $startdatetime = strtotime($row["ss_datestart"] . " " . $row["ss_timestart"]);
   // calculate the end timestamp
   $enddatetime = strtotime($row["ss_dateend"] . " " . $row["ss_timeend"]);
   // calulate the difference in seconds
   $difference = $enddatetime - $startdatetime;
   // hours is the whole number of the division between seconds and SECONDS_PER_HOUR
   $hoursDiff = $difference / SECONDS_PER_HOUR;
   // and the minutes is the remainder
   $minutesDiffRemainder = $difference % SECONDS_PER_HOUR;
   // output the result
   echo $hoursDiff . "h " . $minutesDiffRemainder . "m";
}

You may need to fiddle a bit, but this code should point you in the right direction.

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

Ah thanks Ezzaral, didn't see that icon. :$ Will remember for future reference.

darkagn 315 Veteran Poster Featured Poster

Is it possible to flag a Personal Message as Spam? I received two identical messages from a banned member today but couldn't find a way to report it.

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

This line:

$result = mysql_query("select * from presenters;");

should be:

$result = mysql_query("select * from presenters");
darkagn 315 Veteran Poster Featured Poster

Hi pitulobo and welcome to DaniWeb :),

This can be achieved with a simple join in the two tables on the key InvNo. Have a try at it and post back if you are struggling with your code and we will see where you have gone wrong.

darkagn 315 Veteran Poster Featured Poster

You can use single quotes to do this. Take a look at the difference between these lines of code and you will see:

$foo = "Something witty...";
$blah = "Something strange...";
$string = "$blah"; // $string now equals the string {Something strange...}
$string = '$foo'; // $string now equals the string {$foo}
$string = "1 2 3 '$blah' 4 5 6"; // $string now equals the string {1 2 3 'Something strange...' 4 5 6}
$string = '1 2 3 "$foo" 4 5 6'; // $string now equals the string {1 2 3 "$foo" 4 5 6}

You can also use the backslash character ( \ ) to escape certain characters in a string, like so:

$string = "I am escaping \$the dollar sign..."; // $string now equals the string {I am escaping $the dollar sign...}

Hope this helps...

darkagn 315 Veteran Poster Featured Poster

You need to specify the relative path from the script calling the constructor, not from the class. For example, if your class and xml file are in the /classes folder, then you need to call $mysql = new sqlConnection("classes/path.xml");

I know that may seem strange considering that the class is in the same folder, but the path to a file is either relative to the script being run or absolute if specified in that way.

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

You could try:

if(isset($_POST["restroomsyn"]))
  $restroomsyn = ($_POST["restroomsyn"]);
else
  $restroomsyn = null;

Then when you are inserting use is_null to check for null and set the column to NULL in this situation.

darkagn 315 Veteran Poster Featured Poster

Hi saher_omer,

In future, please start a new thread if your question is not directly related to the original poster's problems.

But to answer your question, there are many examples on the net of an SQL select statement. Google will provide millions of them. Here is a good one.

darkagn 315 Veteran Poster Featured Poster

Not sure of the maximum size, but you may want to think about the effect of having a 1MB script on your bandwidth and website performance during peak periods.

darkagn 315 Veteran Poster Featured Poster

Hi shariqmsit and welcome to DaniWeb :)

"hospital administration database" is pretty abstract. I think you need to define what is required a bit more than that before you even think about database design.

darkagn 315 Veteran Poster Featured Poster

Well I thought I'd given you a pretty good outline of what you need to do. If you are after code example of how to implement a JButton's click behaviour, try this tutorial.

Like I said these concepts aren't simple, if you don't know basic java program elements and flow then you may struggle with your implementation.

darkagn 315 Veteran Poster Featured Poster

The main method in a java application has the following signature:

public static void main(String[] args)

If you are a beginner I would suggest starting with something a bit simpler than a JButton's click method. But the theory behind it is to add an ActionListener to your button. This listener has an actionPerformed method that is called when the action is taken on the component, in this case pressing the button. Inside that method you can call another method or do whatever you like, such as JTextField.setText...

darkagn 315 Veteran Poster Featured Poster

Without the parameter, the printer_open function attempts to find the default printer from your php.ini settings. If it can't find them it will then use the default printer of the machine running the script. It is always recommended to specify the printer name if known, or prompt the user for the printer if possible.

EDIT: Check out the printer_list() function, it might help you specify the printer if you have no other way of determining it.

darkagn 315 Veteran Poster Featured Poster

Thank you both for the advice, I didn't know about the function_exists function. That's a great tip :)

darkagn 315 Veteran Poster Featured Poster

Hi all,

I have seen code of the form:

if(file_exists("foo.php")
  include("foo.php");
else
  include("blah.php");

As far as I know, this is perfectly legal in php. What I was wondering was is it possible to do the following in in-line code in PHP?

if(file_exists("foo.php")
  // contains a specialised version of myFoo function
  include("foo.php");
else
{
  // define the default function here
  function myFoo($param)
  {
      // do something here
  }
}

So in other words I want to be able to define a function in my PHP code only if the specialised version does not exist. I need to do this without the use of classes and inheritance if possible, and I can't include a second file at this stage, just wondering if the above code is legal or not.

Thanks in advance for your thoughts and time.

Regards,
darkagn

darkagn 315 Veteran Poster Featured Poster

Yep that works too, my example was to show you the method behind the madness :P

darkagn 315 Veteran Poster Featured Poster

I don't believe that you need a profile_id, just use the user_id as the key in the profiles table. When you create a new user, insert a record into both tables. When you delete a user's account, delete from both tables.

To access the profile of a user, you can then select * from profiles where user_id = <userId> . To get their user details, replace the word profiles in that statement with users. If you want to see both the user details and the profile for each user, the following simple join can achieve this:

select * from users
inner join profiles
on users.user_id = profiles.user_id
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

Use the SUBSTRING function.

SELECT SUBSTRING(ImageLink, 2, 100) FROM TheTable -- the 2 indicates start at index of 2, the 100 will give you the next 100 characters in the string "ImageLink"
darkagn 315 Veteran Poster Featured Poster

You can simply pass the Count to the Max function like so:

select max(count(ProgramType)) as MAXCOUNT 
from credential_state 
group by ProgramType
darkagn 315 Veteran Poster Featured Poster

Ah ok, sorry I misunderstood what you were trying to do.

The SUBSTR() function might be able to help.

SELECT TARIFF FROM RATES WHERE COUNTRYCODE = SUBSTR(<phonenumber>, 0, 3)

You probably have to fiddle with it, but basically this will return the tariffs for all countrycodes that match the first three digits of the phone number. Again, this is assuming that the length of the country code is 3. You may need an if-statement and select country codes of length 2 if no match is made on the first three and finally the first digit only if no match is found there.

darkagn 315 Veteran Poster Featured Poster

Looks like COUNTRYCODE is a VARCHAR(3) (that is a maximum of 3 character string) so I don't think you can store the Bahamas code in that field. However if you want all country codes that start with a 1, the following may help:

SELECT TARIFF from RATES where COUNTRYCODE like '1%'
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

In order to run a method that takes an array of integers and returns their sum, your method will need the following signature:

public static int sumArray(int[] anArray)

Then, instead of having the line sum = sum + anArray; in your main method, after your loop you can call your method like so:

sum = sumArray(anArray);

I'll leave it to you to figure out exactly what needs to go in the sumArray method, but it is fairly simple so don't over-complicate it.

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

yes, the switch is definitely something innovative, any programming language should think of offering!But at the moment no support for such switch statements yet, which can evaluate the expression.
one more thing, what if the session variable "user_id" wont be set.
$level will be nothing and will be passed as it is to the function and the query inside it will fail, hence no return from it.

Actually PHP does support the switch statement, the original poster was just using it incorrectly. A simple example of a PHP switch statement might be:

// get the mode of operation from the URL
if (isset($_GET["mode"]))
   $mode = intval($_GET["mode"]);
else
   $mode = 0;
// decide what to set something else to based on the mode
switch($mode)
{
   case 0: // this means that $mode == 0 is true
      $car = "Ferrari";
      break;
   case 1:
      $car = "Porche";
      break;
   case 2:
      $car = "Chevrolet";
      break;
   case 3:
      $car = "Dodge";
      break;
   default: // gets to here if $mode < 0 or $mode > 3
      $car = "Ford";
}

Of course this could be written with a long if-else statement, but personally I think the switch is neat in this situation. The original poster had case-statements attempting to evaluate a true/false themselves which is incorrect in syntax.

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

There are lots of free site map generator tools out there. One of the most popular ones is Google's phpSitemapNG. Here is a link to the home website for this tool.

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

The call to mysql_query returns true if it is successful, false if it is not. You can therefore call it inside the condition of an if-statement. I believe you can do that in C++ too if the function call returns a boolean result. In PHP you don't HAVE to use the returned result of a function call, so w3schools example just ignores it and calls the function without worrying about what is returned. I am sure that their example is just an example, your code is better because it will handle the situation of when the query fails.

darkagn 315 Veteran Poster Featured Poster

Yes, that looks good to me. So let's look at what you need to do for your countOneLetter method. The method signature will look like this:

public int countOneLetter(File inputFile, char searchLetter)

You can get this from the description given to you:
countOneLetter() takes a File object and a letter, and returns the number of occurrences of the specified letter in the file (in uppercase or lowercase).
If you look at what I've done with the method signature, I have said that we will return an int (you can't have fractions of occurrences) and we require the file and the letter that we are searching for.

Ok, so how to structure the method? First we need to set up a variable to store the number of times the letter occurs in the file. Let's call it count and we start at 0 because we haven't found any occurrences yet. So add the following line to your method, right at the start:

int count = 0;

Next we need to check whether the char that was passed in is a letter, and whether it is upper or lower case. The Character.isLetter(), Character.isUpperCase() and Character.isLowerCase() methods will help you here. If it's not a letter, you can either throw an exception or return your count of 0. If it is a letter, and it's lower case, we need to work out what it's upper case letter is before we search the file. Similarly, if we have an …

darkagn 315 Veteran Poster Featured Poster

I believe it is possible to set a flag to generate javadoc for private/protected fields and methods. I think its -private or something like that. Google might be able to help you some more on that.

darkagn 315 Veteran Poster Featured Poster

Hi alreem,

We can only help you if you show that you have made some sort of an attempt. Do you have an algorithm or some code that you have tried? We may be able to point you in the right direction if we can see what you are thinking...