Jump to content

EP

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Everything posted by EP

  1. Ok, I got it to work. <?php $oneweek = date('Y-m-d H:i:s', strtotime('-1 week')); $oneweekago = strtotime($oneweek); echo "oneweek: " . $oneweek . "<BR>\n"; echo "oneweekago: " . $oneweekago . "<BR>\n"; ?> Works just fine. Thanks for the help.
  2. I tried that already, it's not working for me. Here, try this: <?php $now = date('Y-m-d H:i:s'); $now2 = strtotime($now); $oneweek = strtotime("+1 week",$now); $oneweek2 = strtotime("+1 week"); $oneweekago = $now2-$oneweek; $oneweekagosearch = date('Y-m-d H:i:s',$oneweekago); echo "now: " . $now . "<BR>\n"; echo "now2: " . $now2 . "<BR>\n"; echo "oneweek: " . $oneweek . "<BR>\n"; echo "oneweek2: " . $oneweek2 . "<BR>\n"; echo "oneweekago: " . $oneweekago . "<BR>\n"; echo "oneweekagosearch: " . $oneweekagosearch . "<BR>\n"; ?> Here's the output I got from that: now: 2009-05-30 08:25:23 now2: 1243697123 oneweek: 606809 oneweek2: 1244301923 oneweekago: 1243090314 oneweekagosearch: 2009-05-23 07:51:54 And I still got a line in the error.log that says "A non well formed numeric value encountered" I need the output from the $oneweek line to be a certain way or it throws the rest of the script off. Maybe there is something else I can use for that line besides strtotime?
  3. Hello, I need a little help here. I can't figure out what seems to be the problem with my code here. Everytime my script executes, I get a log full of this type stuff over and over again: [sat May 30 07:23:36 2009] [error] [client 127.0.0.1] PHP Notice: A non well formed numeric value encountered in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\topsongs.php on line 234 Here is an example of the code I am having a problem with: $now = date('Y-m-d H:i:s'); $now2 = strtotime($now); $oneweek = strtotime("+1 week", $now); $oneweekago = $now2-$oneweek; $timeplayedaddstr = strtotime($timeplayedadd); if($timeplayedaddstr>$oneweekago){ $topsongs[$arraytitle]['playsthisweek'] = $topsongs[$arraytitle]['playsthisweek'] + 1; }; Hopefully that's enough code to give you an idea of what I am trying to do. $timeplayedadd is a variable which is defined in each entry in my array. It is time and date of the entry in the default mysql format. The line that generates the "non well formed numeric value" error in the log is: $oneweek = strtotime("+1 week", $now); Any idea of how to fix this?
  4. Maybe I didn't explain this clear enough. I have a list of results from a mysql query. I need to know how to modify the "title" field in each result of the array.
  5. Ok, I have an array, it's actually the results from a mysql database query. Here's an example: Array ( [0] => Song 2 [title] => Song 2 [1] => Blur [artist] => Blur [2] => 2008-11-12 03:59:51 [timeplayed] => 2008-11-12 03:59:51 ) Array ( [0] => Pale Shelter [title] => Pale Shelter [1] => Tears For Fears [artist] => Tears For Fears [2] => 2008-11-12 03:55:15 [timeplayed] => 2008-11-12 03:40:15 ) Array ( [0] => My Own Prison (Radio Edit) [title] => My Own Prison [1] => Creed [artist] => Creed [2] => 2008-11-12 03:52:01 [timeplayed] => 2008-11-12 03:30:00 ) The results list is much bigger than that but you get the idea. I'm trying to use array_map() to go through each result and modify the "title" value only. I'm trying to get it to remove the song version from the title string like where it says "(Radio Edit)" so the third entry's title value above would only output "My Own Prison" when I go to list the array. I have the code for modifying the string when it is in a while($row = mysql_fetch_array($result)) loop but I just can't get array_map() to modify only that part of the array and print the result. Can someone maybe give me some example code on how to do this? EDIT: Sorry, I forgot to post the code I have so far. Here: $result = mysql_query("SELECT title, artist, timeplayed FROM `songhistory` ORDER BY title"); function stripversion($title) { $title = $row['title']; $condition1 = strripos($title, 'edit'); $pos = strrpos($title, '('); if($pos > 0) { if($condition1 > 0 ){ $title = substr($title, 0, $pos); } return $title; } $titlesfixed = array_map("stripversion", $result); print_r($titlesfixed);
  6. Would the best way be to put the results from mysql_fetch_array($result) into a new array and combine, count, and sort within that new array? How would I do that? Does anybody have any sample code?
  7. Oh ok thanks. I'll be sure to keep that in mind and make the appropriate changes. The data that is pulled from the database. Ok, here is an example. Say these entries are pulled out of the DB: Song 2, Blur 3PM Iris, Goo Goo Dolls 2:57PM Minerva, Deftones 2:53PM Song 2, Blur 1PM I want to combine the entries that have the same title and artist values because that is just the same song being played multiple times. So if I was using the data above, I'd want the result to look like.. Title, Artist (Hits) Song 2, Blur (2) Iris, Goo Goo Dolls (1) Minerva, Deftones (1)
  8. I'm trying to build a PHP script that displays the top 30 (or whatever number) played songs. My mysql database is configured so that each time a song plays, an entry is made in the DB. So if a song shows has 8 entries then that means it has been played 8 times. I have no problem selecting the necessary data from the DB. The problem is I'm not sure how to manipulate it to get the desired result. Here is what I have so far: <?php mysql_connect("localhost", "root", "password"); mysql_select_db("songhistory"); $numbertop = $_GET["numbertop"]; $timeperiod = $_GET["timeperiod"]; # Grab entries for last 7 days only $now = date('Y-m-d H:i:s'); $now2 = strtotime($now); $date2 = strtotime("+1 week",$now); $timefinal = $now2-$date2; $timeplayedsearch = " > ' " . date('Y-m-d H:i:s',$timefinal) . " ' "; $result = mysql_query("SELECT title, artist, timeplayed FROM `songhistory` WHERE timeplayed " . $timeplayedsearch . " ORDER BY title"); echo "<TABLE align='center' cellpadding='2' cellspacing='0' border='0'>"; echo "<TR><TD align='center' colspan='4'><FONT FACE='ARIAL' SIZE='3'>TOP 30 SONGS</FONT></TD></TR>"; echo "<TR><TD align='center'><FONT FACE='ARIAL' SIZE='2'><B>No.</B></FONT></TD><TD align='center'><FONT FACE='ARIAL' SIZE='2'><B>TITLE</B></FONT></TD><TD align='center'><FONT FACE='ARIAL' SIZE='2'><B>ARTIST</B></FONT></TD><TD align='center'><FONT FACE='ARIAL' SIZE='2'><B>TIME PLAYED</B></FONT></TD></TR>"; $i=1; while($row = mysql_fetch_array($result)) { echo "<TR>"; echo "<TD align='center'><FONT FACE='ARIAL' SIZE='1'>" . $i++ . "</FONT></TD>"; echo "<TD><FONT FACE='ARIAL' SIZE='1'>" . strtoupper($row['title']) . "</FONT></TD>" ; echo "<TD><FONT FACE='ARIAL' SIZE='1'><B>" . strtoupper($row['artist']) . "</B></FONT></TD>" ; echo "<TD align='center'><FONT FACE='ARIAL' SIZE='1'>" . $row['timeplayed'] . "</FONT></TD>" ; echo "</TR>"; } echo "</TABLE>"; mysql_close(); ?> Any help would be appreciated.
  9. Without the -1, the strings that don't contain a ( aren't even displayed. I have this running in a looping "while" statement. I'm trying to figure out how to put an if else statement around it.. If the string contains ( then it runs your code. Else, leave the string alone.
  10. It works but the strings that don't contain any ( characters are getting the last character of the string cut off. Example: test (123) --> test test (123) (456) --> test (123) test123 --> test12
  11. Hey guys. I have a string. I want to find the last ( character in the string, strip out the character and anything after it. If there is a ) character before the last ( then that means there is another set of brackets which I want to leave alone. I just want to find the last bracket, delete it, and everything after it. I also need it to only search for the last ( because some times there is not a closing ) bracket... some of the strings from my source are cut off. How would I go about this? I'm new to PHP so I'm a little lost.
  12. Oops. Ok, it shows success and the database was updated. Thanks alot man.
  13. Ok. " INSERT INTO table VALUES ( 'title', 'artist', 'album', '2008/07/15 03:10:17' ) "
  14. Hey guys. I need a little help here. I have a program that spits out a text file with a complete INSERT query to insert data into a mysql database. After the text file is updated, this php file is supposed to be run using GET instead of POST so it can take the new info from the file and run the command. I tried to call the file up in a web browser and checked the database but it was not updated. Here is the code: <? mysql_connect("localhost", "root", "password"); mysql_select_db("database"); $file=file_get_contents("output_file.txt"); mysql_query($file); mysql_close(); ?> The final mysql_query result should be something like... mysql_query("INSERT INTO table VALUES ('value1', 'value2', 'value3', 'value4')"); ..because that's what the text file contains. I don't understand what I am doing wrong. Any help would be appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.