Jump to content

182x

Members
  • Posts

    179
  • Joined

  • Last visited

    Never

Everything posted by 182x

  1. Thanks, for testing purposes is there anyway to 'login' as different users at the sametime without having to use different browsers? Thanks.
  2. Hey guys, I am using session variables in order to insert the username into the database when the user submits a form. I was just wondering as I don't fully understand session variables could this cause any problems? For example if one user logs in and then another will the first users session vars be overwritten? (I am only making a localhost site which is run locally, so if I did this on my machine logging in two different users one in firefox one in ie would this also be ok?) Thanks.
  3. Thanks for pointing that out. So just to be clear if the above code was now executed and there was no testId equal to 7, its still ok? thanks.
  4. Hey guys, I am going to write a php script to delete some records based on values supplies by the user. I was just wondering if the query is correct but there are no records to delete for example if this query was executed but there was no testId 7, would an error occur or would the query be performed but just not delete any records? Thanks. (not at a testing machine at the mo or would test this out myself) $testId = 7; $q="DELETE FROM test WHERE testId = $testId"; mysql_query($q, $link_id)or die(mysql_error()); Edit: Error in code my bad.
  5. Hey guys, I was trying to get the code below to count the number of times a year occurs in each query and then store the total amount along with the year. So if table 1 had 2007 appear 3 times and table2 had 2007 appear 3 times the final out put should be in that $amountAll[] = 6 and $amountYear = 2007. I was just wondering where i went wrong? $getAll = "SELECT year, count(*) FROM table1 GROUP BY year"; $queryAll = mysql_query($getAll, $link_id) or die(mysql_error()); $getAll2 = "SELECT year, count(*) FROM table2 GROUP BY year"; $queryAll2 = mysql_query($getAll2, $link_id) or die(mysql_error()); $rowAll3[400]; $years = array(); while($rowAll = mysql_fetch_array($queryAll)) { $years[$rowAll['year']] = $rowAll['count(*)']; } while($rowAll = mysql_fetch_array($queryAll)) { if(isset($years[$rowAll2['year']])) { $years[$rowAll2['year']] += $rowAll2['count(*)']; } else { $years[$rowAll2['year']] = $rowAll2['count(*)']; } } ksort($years); // sort array by keys (years) foreach($years as $year => $count) { $amountAll[] = $count; $yearAll[] = $year; }
  6. 182x

    query help

    Hey guys, I have been trying to write the following query in mysql it was made on oracle first just wondering how this can be achieved in mysql? SQL> select yr,sum(cnt) cnt 2 from (select yr,count(*) cnt 3 from test1 4 group by yr 5 union all 6 select yr,count(*) cnt 7 from test2 8 group by yr) 9 group by yr;
  7. 182x

    Logic error

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource the above error occurs with the mysql_fetch_array($res) in the code.
  8. 182x

    Logic error

    Just tried it but it didn't procude any result when inserting it into the array.
  9. 182x

    Logic error

    Sorry maybe I am not being clear I have to be able to count the number of time the years occur from 2 different and unrelated tables and store this information in an array but I only want the actual year value to be stored once along the number of times that year occurs.
  10. 182x

    Logic error

    That won't work as I am dealing with data from both tables and need the total of all the year amount but only keep one of the actual year values for example one table could have 2007, 50, 2007, 50 and the other table could have 2007, 10, 2007, 10. So i need just 2007, 120.
  11. hey guys, trying to make the following code work but there is a problem with the while just wondering how to fix that so that the year will be stored just once and with the total amount of times it appears in each table? Thanks. $getAll = "SELECT year, count(*) FROM test1 GROUP BY year"; $queryAll = mysql_query($getAll, $link_id) or die(mysql_error()); $getAll2 = "SELECT year, count(*) FROM test2 GROUP BY year"; $queryAll2 = mysql_query($getAll2, $link_id) or die(mysql_error()); $rowAll3[4]; while($rowAll = mysql_fetch_array($queryAll) && $rowAll2 = mysql_fetch_array($queryAll2)) { if ($rowAll['year'] == $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']+$rowAll2['count(*)']; } if ($rowAll['year'] != $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']; } if ($rowAll2['year'] != $rowAll['year']) { $rowAll3[1] =$rowAll2['year']; $rowAll3[0] =$rowAll2['count(*)']; } $amountAll[] = $rowAll3[0]; $yearAll[] = $rowAll3[1]; printf("<pre>%s</pre>\n", print_r($rowAll3, 1));
  12. Hey guys,, just wondering where I went wrong with this code, I am trying to ensure that the an array only gets filled with 1 year and the total times that year appears in both tables but the problem is that data is only being supplied once from the second table. Just wondering how to fix this? Thanks. $getAll = "SELECT year, count(*) FROM test1 GROUP BY year"; $queryAll = mysql_query($getAll, $link_id) or die(mysql_error()); $getAll2 = "SELECT year, count(*) FROM test2 GROUP BY year"; $queryAll2 = mysql_query($getAll2, $link_id) or die(mysql_error()); $rowAll3[4]; while($rowAll = mysql_fetch_array($queryAll) && $rowAll2 = mysql_fetch_array($queryAll2)) { if ($rowAll['year'] == $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']+$rowAll2['count(*)']; } if ($rowAll['year'] != $rowAll2['year']) { $rowAll3[1] =$rowAll['year']; $rowAll3[0] =$rowAll['count(*)']; } if ($rowAll2['year'] != $rowAll['year']) { $rowAll3[1] =$rowAll2['year']; $rowAll3[0] =$rowAll2['count(*)']; } $amountAll[] = $rowAll3[0]; $yearAll[] = $rowAll3[1]; printf("<pre>%s</pre>\n", print_r($rowAll3, 1)); }
  13. Hey guys, I have two different and unrelated tables and I have done a query to extract infor mation from it and I also have preformed a query to extract information from another table. I was wondering using PHP and my sql is it possible to perform some form of check so that if the year in table1 equals 2007 and the count is 3 and the year in table 2 is 2007 and the count is 1 so the counts can be added together and im just left with one 2007 value. So the final out put would be 2007 and 5? $sql1 = "SELECT year, count(*) FROM table1 GROUP BY year"; $query1= mysql_query($sql1, $link_id) or die(mysql_error()); $sql2 = "SELECT year, count(*) FROM table2 GROUP BY year"; $query2= mysql_query($sql2, $link_id) or die(mysql_error()); //don't know what to do here
  14. Hey guys, I am trying to put values in the array as follows so they can be used for displaying a graph, the problem I am having is that if in one table there is a user called john instead of counting john as 11 in total it will count 8 from one table and 1 from another and display it this way. Just wondering how to solve this problem. $get = "SELECT Username, count(*) FROM table1 GROUP BY Username UNION ALL SELECT Username, count(*) FROM table2 GROUP BY Username "; $query = mysql_query($get, $link_id)or die(mysql_error()); while($row = mysql_fetch_array($query)) { $data[] = $row[1]; $leg[] = $row[0]; }
  15. Hey guys is there a method in php that will auto refresh the page once it is called? I have a dynamic image which should change based on the parameters but often it does not update and I have to press the F5 key. I am using the <img> tags so is there a php method to refresh a page or another way round this problem? Thank you
  16. does that still only produce one 2007 value if there are three 2007 values in table1 and four 2007 values in table2?
  17. Thanks, if its done that way is there a method that can limit the result for example if 2007 appears 8 times can it be limited to just appearing once?
  18. Still can't figure this one out, anyone got anymore ideas? Thanks.
  19. just looked the php manual for umask I don't really understand it, what is it used for? Thanks.
  20. Hey guys, when using the unlink feature in php i get an error which states I do not have enough permission do to this, I was wondering how to I get enough permission in windows? thanks
  21. I get this error: Column 'year' in field list is ambiguous
  22. Hey guys, I am trying to create a query in order to dynamicly popular a listbox however I am trying to fill the listbox with years such as 2007 etc based on if they are stored in the data base. The problem is that two tables have to be checked that have no relation to eachother but this caues the problem of duplication so if both tables have 2007 it will appear in the list more than once. I was just wondering if there is a way round this? Thanks. $years= "SELECT * FROM table1; $qyears = mysql_query($years, $link_id) or die(mysql_error()); $years2= "SELECT * FROM table2; $qyears2 = mysql_query($years2, $link_id) or die(mysql_error()); if (mysql_num_rows($qyears2) > 0 || mysql_num_rows($qyears1) > 0) { ?> <select name="years"> <?php //don't know what do do here while($row = mysql_fetch_assoc($qyears)) { ?> <option value="<?php echo $row['year']; ?>"><?php echo $row['year']; ?></option> <?php } } ?> </select>
  23. 182x

    crypt()

    Thanks for the reply, does the hash code have to be specifically put into the DB or is it ok to just put the variable into the db once the hash has been performed for this method to work?
×
×
  • 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.