Jump to content

richei

Members
  • Posts

    90
  • Joined

  • Last visited

Posts posted by richei

  1. Well, removing the COUNT did the trick, and also realizing that i was using the wrong variable, had $username instead of $comment.  Once i made those changes, it started working.  Thanks again for the quick help :)

     

    For some reason i can't mark Barand's suggestion as what solved it.

  2. Not really sure what forum this would be a good fit for, but basically, I use a combination of jquery and php to display comments.  I was going fine displaying the last comment, but now I have to display all the comments.  I tried using some code I use to write pull down boxes, but that didn't work.  I'm sure it could be done using json arrays, but I don't know how to process the results using jquery.

     

    jquery code:

     

    //gets comments for initial secret
       var quid = "quid=<?=$ans['quid']?>";
       $.post("inc/comments_system.php", quid, function(data) {
        if(data.number > 0) {
         $("#comm").html("<p><a href='#'>"+data.number+"</a></p>");
         $("#cbox").show();
         $("#cdisplay").show().html(data.comment);
         $("#quid").attr("value", data.quid);
        } else {
        $("#comm").html("<p><a href='#'>"+data.number+"</a></p>");
        $("#quid").attr("value", data.quid);
       }
      }, "json");

    PHP code

     

    $q = mysql_query("SELECT COUNT(oid) as num, comment, username, oid, createdon FROM comments WHERE oid = $_POST[quid] ORDER BY createdon") or die(mysql_error());
     
      if(mysql_num_rows($q) != 0) {
       while($ans = mysql_fetch_assoc($q)) {
        $username .= "<div style='width: 95%; margin: 0 auto'>".$ans['comment']."<br /><div style='font-style: italic; text-align: right;'> -$ans[username]@ ".date('m-d-y G:i.s', strtotime($ans['createdon']))."</div></div>";
        $num = $ans['num'];
       }
       $ret = array("number" => $num, "comment" => stripslashes($comment), "quid" => $_POST['quid']);
      } else {
       $ret = array("number" => 0, "quid" => $_POST['quid']);
      }
    echo json_encode($ret);
    

    I just need to know what to do to get this to work.

  3. I'm in the mist of doing a login script for a new site.  I have the script working, just as long as you get it right the first time, because after that, it seems to hang on the delay.  Script is below

    $("#login_button").click(function() {
      $.post("inc/login.php", $("#loginForm").serialize(), function(data) {
       var login = data.login;
       var message = data.message;
       if(login == true) {
        $("#login").empty().delay(5000).fadeOut('slow');
       }
       if(login == false) {
        $("#login_window").css('visibility','hidden');
        $("#message").css('visibility','visible').html(message);
        $("#message").delay(4000).queue(function() {
         $("#message").empty().css('visibility','hidden');
         $("#login_window").css('visibility','visible');
        });
       }
      }, "json");
    });

    Basically, its supposed to show the returned error message for 4 seconds, then show the login form again.  I'm using a regular button, not the submit type button.  I don't have any errors in firebug.  Anyone have any ideas?

     

    (i know about show and hide, but those caused entirely to many problems).

  4. those indexes aren't correct though, that's being based off of the combined array.  I got it fixed any working though.  I didn't actually have to tell it what the numbers were, just had to remove the quotes, which i accomplished with an if statement.

     

    for ($c=0; $c < $num; $c++) {
        $lines[$c] = trim(mysql_real_escape_string($lines[$c]));
        if(!is_numeric($lines[$c])) {
         $lines[$c] = "'".$lines[$c]."'";
        }
        $lines[10] = str_replace(',', '', $lines[10]);
        $lines[11] = str_replace(',', '', $lines[11]);
        $lines[13] = str_replace('$', '', $lines[13]);
       }

    This script is completely working now.  Thanks for all the help :)

  5. ok, using that function, this is what i came up with

     

    $row = 1;
    if(($handle = fopen($report, "r")) !== FALSE) {
      while(($lines = fgetcsv($handle, 1000, ",")) !== FALSE) {
       $num = count($lines);
       $row++;
       for ($c=0; $c < $num; $c++) {
        $lines[$c] = trim(mysql_real_escape_string($lines[$c]));
        $lines[$c] = "'".$lines[$c]."'";
        $lines[10] = floatval(str_replace(',', '', $lines[10]));
        $lines[11] = floatval(str_replace(',', '', $lines[11]));
        $lines[13] = floatval(str_replace('$', '', $lines[13]));
       }
       $na[0] = $start;
       $na[1] = $end;
    
       $new = array_merge($na, $lines);
     
       $inst = "INSERT INTO {$companyTbl} (" . implode(', ', $sqlFields) . ") VALUES (".implode(", ", $new).")";
       echo $inst."<br>";
      }
      fclose($handle);
    }

    The only thing i need to figure out is how to ignore the 1 line.  There's a header row that i need don't need to import.  I tried changing $c to 1 and doing $num-1 in the for loop, but that didn't work.

  6. I have to keep the start and end dates dynamic so i don't have to create an array.  I don't know that i'll be there another year and the person taking my spot may not know to go into the code and change file names in the array.  This way, i don't have to worry about it

     

    This is what i'm using to get rid of the $

    floatval(ereg_replace("[^-0-9\.]","", $arr[13]));

     

    I know ereg is depreciated, but i don't know the preg_replace equivalent.  I tried str_replace and it didn't seem to work.

     

    Sample inputs that would give this script issues

     

    Stuart Street Timelapse 28/05/2013,http://www.youtube.com/watch?v=8WTelFJgNrQ,j2yanlol,,Limbo (7th Hour Instrumental)-Noah Becker,USA2P1265247,Marta Krupa,VG Group,"Dance,electric,pop,club,great,female,zedd,dea",0,2,2,Sound Recording,$0.01

     

    NIGHT CLUB GROOV3 - DANCE FITNESS WORKOUT - WITH BENJAMIN ALLEN,http://www.youtube.com/watch?v=#NAME?,dancesweatlive,,Dance Sweat Live,USQY51161867,,VG Group,,30,"4,814","4,844",Composition,$6.44

     

    It would have an issue with both of those because of what's inbetween the quotes.  In the first one, the person put tags where the video title is supposed to be and with the 2nd one, the column is formatted

     

    The first one would get split up like (this is after i combined the dates and content arrays, the start and stop dates aren't included in the file contents).

     

    Array
    (
        [0] => 2014-01-01
        [1] => 2014-01-31
        [2] => '[Devpro Speed Duel] War Gods/Bujin vs Various Decks'
        [3] => 'http://www.youtube.com/watch?v=uZQDiQAlAzo'
        [4] => 'UnlimitedEchoe'
        [5] => ''
        [6] => 'Limbo (7th Hour Instrumental)-Noah Becker'
        [7] => 'USA2P1265247'
        [8] => 'Marta Krupa'
        [9] => 'VG Group'
        [10] => '"Dance'
        [11] => 'electric'
        [12] => 'pop'
        [13] => 'club'
        [14] => 'great'
        [15] => 0
        [16] => 'zedd'
        [17] => 'dea"'
        [18] => '0'
        [19] => '44'
        [20] => '44'
        [21] => 'Sound Recording'
        [22] => '$0.01 '
    )

    and the 2nd would be

    Array
    (
        [0] => 2014-01-01
        [1] => 2014-01-31
        [2] => 'NIGHT CLUB GROOV3 - DANCE FITNESS WORKOUT - WITH BENJAMIN ALLEN'
        [3] => 'http://www.youtube.com/watch?v=#NAME?'
        [4] => 'dancesweatlive'
        [5] => ''
        [6] => 'Dance Sweat Live'
        [7] => 'USQY51161867'
        [8] => ''
        [9] => 'VG Group'
        [10] => ''
        [11] => '30'
        [12] => '"4'
        [13] => '814"'
        [14] => '"4'
        [15] => 844
        [16] => 'Composition'
        [17] => '$6.44 '
    )

     

    In total, there's only supposed to be 15 keys

  7. I have a csv file that i'm trying to import.  I've looked at a few tutorials, but so far, nothing really seems to help me with these issues.

     

    Issue 2 - getting the start and stop date into the csv array.  I was simply merging the two, but ran into other problems due to how i was exploding the content.  I had this solved and working great using sscanf and a switch.

     

    list($Y, $m) = sscanf($filen, '%s %s - %s');
    
        switch($m) { // i have 1 for each month, just not listed here, to long
            case 'Jan':
                $start = date('Y-m-d', strtotime($Y.'-01-01'));
                $end =  date('Y-m-d', strtotime($Y.'-01-31'));
                break;
        }

     

    Issue 3 - changing string numbers to int numbers.  I have 2 that are saved like "4,855" and 1 that's saved liked $0.05.  The datatype for regular numbers are simple int, but the last one is float.  I had fixed those issues before by changing the strings to numbers using (int) and floatval(),

     

    Issue 4 - doing the actual insert using 1 query.  I'm hoping there's a way to do just 1 query instead of first inserting the dates and then running an update query with the additional info.

     

    The old script i had was exploding the contents on the , but thanks to how the file was saved, the numbers i mentioned above were messing things up horribly, and some one put tags in the title column for some entries.  So, doing it that way is out unless there's some way of selectively exploding content.  I had the other issues fixed too.

     

     

    I'm hoping someone has some ideas on how i can get this thing working.

  8. I found a way around the first issue.  Instead of trying to mess with the year, i can use the period.  When it hits 1, i need to back a year off and if not, then i use the regular year.  and yes, 14 is the year.  Anyone have any ideas for the 2nd issue?

  9. change

    mysql_query("INSERT INTO CodigoF (NOMBRE,PW) VALUES ('$_POST[nombre]','$_POST[pw]')",$con);
    echo "datos insertados";

     

    to

     

    if(is_numeric($_POST['nombre'])) {
       $nombre = mysql_real_escape_string($_POST['nombre');
    } else {
       $err[] = "Must be a number";
    }
     
    if(is_numeric($_POST['pw'])) {
        $pw = mysql_real_escape_string($_POST['pw');
    } else {
        $err[] = "Password must be a number";
    }
     
    if(empty($err)) {
        $ins = mysql_query("INSERT INTO CodigoF (NOMBRE,PW) VALUES ($nombre, $pw)") or die(mysql_error());
        if($ins) {
             echo "datos insertados";
        } else {
             echo "problemas al insertar datos";
        }
    } else {
       foreach($err as $code) {
           echo $code."<br>";
       }
    }

    His input doesn't need the quotes in the query, they're integers in the database table.

  10. ok, i have 2 questions.

     

    1st question - I have a script that i use to execute a java class from apple to pull our sales reports each month, set off from a cronjob.

    <?php
    $cc = array('AE','AU','CA','CH','DK','EU','GB','HK','ID','IL','IN','JP','MX','NO','NZ','RU','SA','SE','SG','TR','TW','US','WW','ZA');
    $cperiod = date("m",strtotime("+2 month")); // fiscal period
    $year = 2014;
    
    $command = array();
    $fname = array();
    
    foreach($cc as $code) {
        $fname[] = "xxxxxxxxx_".$cperiod."14_".$code;
        $command[] = 'cd /home/xxxxxx/public_html/admin/files/ && java Autoingestion music.properties xxxxxxxxxxxx '.$code.' DRR '.$year.' '.$cperiod;
    }
    
    for($i=0; $i < count($command); $i++) {
        if(!file_exists("/home/xxxxx/public_html/admin/files/".$fname[$i])) {
            exec($command[$i], $out, $err);
        } else {
            echo $fname." already exists\r\n";
        }
    }
    
    if(isset($out)) {
        foreach ($out as $line) {
            echo "$line \r\n";
        }
    } else {
        foreach ($err as $line) {
            echo "$code: $line\r\n";
        }
    }
    ?>

    My issue won't crop up until January 2015 rolls around.  I'm looking for a way to not have to go in every year and change years.  If not, then i'll just have to set up 4 years ahead.

     

     

    2nd question - We just recently started getting sales reports from youtube and the report doesn't include a start or stop date.  Without using any manual input (which i'm trying to avoid at all costs), the only way i have of getting the time frame is from the file title (ex. 2014 Jan - Claims Report.csv).  What i'm looking for is a way to set the start and stop date into an array using the file title without having to use a crap load of if statements or a seriously long switch.  The only other way i know to do this would be to use manual date input and i really want to avoid that, because it means a lot more programming for me.

  11. If I use this

    $(document).ready(function() {
     $('#submitInfo').click(function(e){
      e.preventDefault();
      var data = $('#genit').serialize();
     
      $.ajax({
       url: 'inc/ajax_submit_iTpackage.php',
       data: data,
       type: "POST",
       cache: false,
      
       success: function(result) {
        $("#submit_suc").html(result);
       }
      });
     });
    }

    The page doesn't up at all, all I get is the progress indicator, did I miss something somewhere?

  12. Is there some reason why this function would work in firefox and ie, but not work at all in chrome?

    function submit_info() {
     var data = $("#genit").serialize();
     
     $.ajax({
      url: 'inc/ajax_submit_iTpackage.php',
      data: data,
      type: "POST",
      cache: false,
      
      success: function(result) {
       $("#submit_suc").html(result);
      }
     });
     //$("#submit_suc").delay(3000).toggle('fast');
    }

    I only test in firefox since I like its developer tools, but the guy that was testing it for me uses chrome and was telling me he couldn't submit the information to the database, so I got on Skype and sure enough, it wasn't working at all, and then I tried it on my chrome and it wasn't working, its not even calling the function.

     

    Thus is the button: <input type="button" value="Submit" onclick="submit_info()" />

     

    second question.  I have a rather large amount of windows that have to opened and closed depending on the content being displayed (basically, each menu item has its own article to display in).  These 2 are from the function to make the article visible.

     $("#viewiT").click(function() {
      var tags = ['tickets','news','addnewuser','viewuser','post_news','view_login','view_albums','isales_merge_labels','trends_merge_labels','view_apps','switch_apps','get_itunes'];
      closetag(tags);
      closer('itunes_marketing', 'genitunes');
     });
     $("#geniT").click(function() {
      var tags = ['tickets','news','addnewuser','viewuser','post_news','view_login','view_albums','isales_merge_labels','trends_merge_labels','view_apps','switch_apps','itunes_marketing'];
      closetag(tags);
      closer('get_itunes', 'viewitunes');
     
     
    function closetag(tag) {
      for(var i in tag) {
       if($("#"+tag[i]).not(':hidden')) {
        $("#"+tag[i]).hide();
       }
      }
     }
    

    The other one actually loads the php page into the now visible window.

     

    My question is this: is there a way to slim that down so I don't have to specify each of the main containers? i'm sure i'll be adding more content in there as we grow and add more services.  all it does is look to see what's visible and if it is, close it.  I'm sure there's a much simpler way of doing this.

  13. I've done research on this and from that I gathered that this needs to be changed to allow it to save instead of asking where to download it to.

    function send($filename)
    {
       header("Content-type: application/vnd.ms-excel");
       header("Content-Disposition: attachment; filename=\"$filename\"");
       header("Expires: 0");
       header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
       header("Pragma: public");
    }

    And this is what calls it: $workbook->send('HitlistSubmission_'.$subdate.'.xls'); (its not a "hitlist", its data that we have to send to iTunes to get our users promoted through iTunes).  The entire code isn't relevant.

     

    I'd like to just save the file on the server because the next step in this pain the rear is to do a script to email it to iTunes.

     

    From what I've read, the content-disposition is supposedly doing this, but I've commented it out and it still asks where to save it.

     

    2nd question, I have this being through a website made primarily with jquery.  My function for sending the data to the page is

    function export_xls() {
     var info = $("#paid").val();
     window.open('inc/export_hitlist.php?paid='+info, 'Export');
    }

    Ideally, i'd like to just get a confirmation message back saying all is well, but I've tried everything that I know that would do it, all I can get it to do is return the contents of the xls file.  I deleted that part of the code since i'm not using it now.

     

    any help would greatly be appreciated!

  14. Yes and no.  The start date was set to Date to add in something else, and i had done the end date conversion on another table.  But i forgot to do it on the one i was working with. Probably would help if i wasn't dealing with a cold right now.

     

    i was using date() and strtotime() to change the date format and it was inserting properly, but messed up both columns when i added in the STR_TO_TIME(). 

  15. I copied and pasted what I needed, the datatype is set to DATE.

     

    if($companyTbl == "venzo_app_sales" || $companyTbl == "venzo_itunes_sales") {
      
      /*for each record in the report...*/
      for($i = 1; $i < count($fcontents)-3; $i++) {
       $line = $fcontents[$i];
       $arr = explode("\t", $line);
          
       /*santitise the values*/
       foreach($arr as $key => $value) {
        $arr[$key] = trim(mysql_real_escape_string($value));
        //if(strlen($arr[$key]) == 10) {
        if($key == 0 || $key == 1) {
         $value = "STR_TO_TIME('".$value."', '%m/%d/%Y')";
         //$arr[$key] = date('Y-m-d', strtotime($arr[$key]));
         //$arr[$key] = "'$arr[$key]'";
        } else {
         $arr[$key] = "'".trim(mysql_real_escape_string($value))."'";
        }
       }
       
       if(strtolower($arr[0]) != "total") {
        /*number of fields in the DB exceeds number of fields in the record*/
        if($sqlFieldNum > count($arr)) {
         $error[$i] = true;
         for($a = 0; $a < count($sqlFields); $a++) {
          echo "{$a}) MYSQL: {$a} => {$sqlFields[$a]} - Report: {$a} => {$arr[$a]}<br>";
         }
         echo "# of fields in the table (" . $sqlFieldNum . ") is greater than the # of fields in the report (" . count($arr) . ")!<br />";
                 
         /*number of fields in the record exceeds number of fields in the DB*/
        } else if($sqlFieldNum < count($arr)) {
         $error[$i] = true;
         for($a = 0; $a < count($arr); $a++) {
          echo "{$a}) MYSQL: {$a} => {$sqlFields[$a]} - Report: {$a} => {$arr[$a]}<br />";
         }
         echo "# of fields in the report (" . count($arr) . ") is greater than the # of fields in the table (" . $sqlFieldNum . ")!<br />";
        }
             
        /*if there is no error insert the record into the table else continue onto the next record*/
        if(isset($error[$i]) != true) {
        
         //$sql = "INSERT INTO {$companyTbl}(" . implode(', ', $sqlFields) . ") VALUES ('" . implode("', '", $arr) . "')";
         $sql = "INSERT INTO {$companyTbl}(" . implode(', ', $sqlFields) . ") VALUES (".implode(", ", $arr).")";
         //echo $sql."<br />";
         $ins = mysql_query($sql) or die(mysql_error());
        
         if($ins) {
          copy($report, $path."/".$filen);
         }
        } else {
         echo "Record {$i} not inserted!";
        }
       }
      }
     }
    I just finished deleting all the bad records and uploaded the reports again.
×
×
  • 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.