Jump to content

richei

Members
  • Posts

    90
  • Joined

  • Last visited

Profile Information

  • Gender
    Male

richei's Achievements

Member

Member (2/5)

1

Reputation

  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. I guess i could get that with mysql_num_rows(). If that's all it was, i'm going to scream.
  3. 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.
  4. problem fixed, just had to add .stop to the login_window entry. also reworked it to simplify it some.
  5. there should be a lot on stackflow. when I was looking for a way to center a div, it took me a few minutes to find it. how much time it takes depends on what you search for. try http://stackoverflow.com/questions/2407221/how-to-get-the-height-of-the-screen-using-jquery (took 30 seconds to find btw)
  6. 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).
  7. 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
  8. And i got it to ignore the headers, just added fgets($handle); after the if statement.
  9. 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.
  10. 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
  11. 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.
  12. And that's why I come here I guess I'm stuck having to do a switch for setting the start and stop dates. I can only mark 1 solved, but both were.
  13. 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?
  14. The error is in the query. You need to put single quotes around strings. Php has a built in function to find empty fields - empty(). Not sure where u got what ur using. Also need to choose one, either use myself or mysqli, can't use both. And where is $ run1 coming from?
  15. 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.
×
×
  • 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.