Jump to content

joel24

Members
  • Posts

    760
  • Joined

  • Last visited

Everything posted by joel24

  1. and also check if your sql command is running correctly and if not show the error with the "or die(mysql.error())" after the query... $query='SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"'; print "About to run $query\n"; $sql = mysql_query($query) or die(mysql.error());
  2. you're not inserting the full path into the database...? //Create sql query and insert the values into the database $sql = "INSERT INTO imageUpload (title, thumbpath) VALUES ('$imgTitle', '$thumb_Add_thumb')"; you'd need to change to //Create sql query and insert the values into the database $sql = "INSERT INTO imageUpload (title, thumbpath, fullImageColumn) VALUES ('$imgTitle', '$thumb_Add_thumb', '$filePathFull')"; the fullImageColumn should be renamed to whatever the column is that stores your full image name...? and $filePathFull contains the full file path to that image...
  3. why not just put the filename on the end of hte thumbnail rather than a random number?! i.e. get rid of //Generate a random number to append the filename. $ran = "thumb_".rand () ; $thumb2 = $ran.".jpg"; and replace with //append filename to thumb $thumb2 = "thumb_".$_FILES["imagefile"]["name"]; ...?
  4. you can have a custom error message... but it will show up if any sql errors occur, not just username duplicates. $ok = @mysql_query("INSERT rara mysql command") or die("This username has been taken"); otherwise you'd have to use an sql query to see if that username is taken and then use an if command in the php.. i.e. $username = $_POST['username']; $sql = @mysql_query("SELECT username FROM users WHERE username = $username"); if (mysql_num_rows($sql)) { exit("Username has been taken"); } else { $ok = @mysql_query("INSERT rara mysql command"); } you may want to have something like $errorMessage = "Username has been taken" and call that variable in the page rather than using exit... its pretty ugly
  5. ahh wow, didn't know you could use if statements in mysql thank you!!
  6. thanks, but i need it to find the higher of each column in each row.... and add that so if col1 was greater than col2 in row 23 it would put col1 in the addition, and if col2 were greater than col1 in row 12 it would put col1 in the addition there. anyone?!
  7. Not sure if this is possible in MySQL alone, however, it will greatly help my cause if it is so I'm pursuing it. Say I have a table with columns like this ID Col1 Col2 1 10 20 2 20 15 3 15 30 Is it possible to find the sum of the greater values of col1 and col2 in MySQL... without using php etc..? So it would be 20 + 20 + 30... Any help would be greatly appreciated!
  8. I have been staring at this code for hours and cannot work out what I'm doing wrong, maybe I need a break! Within both the financials and finres tables I have resource, budget, eac, actual, month1, month2, month..., month24. I need to add the values of the budget, eac and actual columns and insert them into their respective finres columns. That is working, however, the problem comes when I try to execute a for loop inside the while loop so that $month1[] is filled with all the different month1 values, and $month2[] is filled with all its values so I can call an array_sum($month1[]) and insert it into the finres table... if that makes sense? here is my code, the trouble starts with the first for loop... unsure (and doubtful) as to whether the proceeding for loops will work //update budget, eac, actual etc into financial resources table $sql = "SELECT * FROM " . $projectid . "_financials WHERE resource = '$resource'"; $addfin = @mysql_query($sql) or die('(F02) Error retrieving financials: ' . mysql_error()); while ($af = mysql_fetch_array($addfin)) { $budget[] = $af['budget']; $eac[] = $af['eac']; $actual[] = $af['actual']; //insert individual month values into respective arrays for($i=1;$i<=24;$i++) { $pre = 'month'.$i; $$pre[$i] = $af["month$i"]; //I have tried putting in echo 'bob'; here but it doesn't even print bob. } } //get sums of arrays $sum_budget = array_sum($budget); $sum_eac = array_sum($eac); $sum_actual = array_sum($actual); for($i=1;$i<=24;$i++) { $pre = 'sum_month'.$i; $post = 'month'.$i; $$pre = array_sum($$post); } //insert into finres table $sql = "UPDATE " . $projectid . "_finres SET budget = '$sum_budget', actual = '$sum_actual', eac = '$sum_eac'"; for($i=1;$i<=24;$i++) { $sum = 'sum_month'.$i; $pre = 'month'.$i; $sql .= ", ".$$pre." = '".$$sum; } $ok = @mysql_query($sql) or die("(F03) Financials Error: " . mysql_error()); I get the "Warning: array_sum() [function.array-sum]: The argument should be an array in ..... on line 197" x24 In other words the for each loop isn't executing and putting the elements into the array?? Please help!
×
×
  • 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.