[PHP-DB] RE: [PHP] need help looping through each record with a query - stumped
could you change this $query2 = ("SELECT Month, Score FROM scores WHERE Username = '$Username'"); to $query2 = ("SELECT count(*) FROM scores WHERE Username = '$Username' and Score >= 75 and Month in ('January', 'December', 'November', 'October')"); $result2 = mysql_query($query2) or die ("Cannot execute query" . mysql_error ()); $tally = mysql_fetch_row($result2); take out the while loop (the one with all the if's in it) and, if I haven't stuffed up somewhere, all will be okay - (btw, I haven't had experience using mysql, but I'm assuming that it's sql is compatable with interbase and oracle) Hope that helps Martin -Original Message- From: Brian Tully [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 8:59 AM To: PHP DB; PHP Subject: [PHP] need help looping through each record with a query - stumped hey folks - i'm stumped. been working on what i thought would be a simple script to cycle through users' records and perform a query. But I can't get the loops right, it seems like only one or two records get updated. Using MySQL, we have about 2000 students enrolled. each month they take a test. if they pass the most recent 3 tests (consecutively) they earn "Certified" status and get a few perks. Somehow the certification status' got messed up. So I'm trying to create a script that will look through each user's test records to see if they've passed the last 3 tests, and if so, change their certification status in the database. Not very elegant since there are so many records in the database (2000 users), but I don't think i have a choice. Anyways, I've tried to loop through each user, and for each user loop through their scores. But the loops aren't working. I'm sure it's something simple and obvious I'm missing but my brain is fried! I'd appreciate it if someone could take a look and offer any advice. It's about 65 lines of code (with comments). thanks in advance! brian = 75)) { $tally++; } if (($Month == 'December') && ($Score >= 75)) { $tally++; } if (($Month == 'November') && ($Score >= 75)) { $tally++; } if (($Month == 'October') && ($Score >= 75)) { $tally++; } } /* the concept is that if a user has taken and passed the last 3 tests, they become certified. so we look at the current month first and go back 3 months, since it may be the beginning of the month and they may not have taken the current months test yet. Since we increase the counter for each passed test, if the counter equals 3 or more this means they have passed 3 tests and are thereby certified. So we update their certification status in the database. */ if ($tally >= 3) { $query1 = ("UPDATE users SET Certification = 'Y' WHERE Username = '$Username'"); $result1 = mysql_query($query1) or die ("Cannot update user to Certified" . mysql_error ()); } } print ("Update complete!"); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] RE: [PHP] need help looping through each record with a query - st umped
i'm converting Brian's php code into sql - he's looking for scores in Oct, Nov, Dec and Jan, that's what I'm doing in the sql, and the if's all have "if score >= 75" which is what I'm doing in the sql too, Brian is getting a total "$tally++" so am I "count(*)"... -Original Message- From: Mehmet Kamil ERISEN [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 10, 2002 11:10 AM To: Martin Towell; 'Brian Tully'; PHP DB; PHP Subject: RE: [PHP] need help looping through each record with a query - st umped If you are querying the Score >= 75 how are you ging to take the "Consecutive" requirement into the account. --- Martin Towell <[EMAIL PROTECTED]> wrote: > could you change this > > $query2 = ("SELECT Month, Score FROM scores WHERE > Username = > '$Username'"); > > to > > $query2 = ("SELECT count(*) FROM scores WHERE > Username = '$Username' and > Score >= 75 and Month in ('January', 'December', > 'November', 'October')"); > $result2 = mysql_query($query2) or die ("Cannot > execute query" . > mysql_error ()); > $tally = mysql_fetch_row($result2); > > take out the while loop (the one with all the if's in it) > and, if I haven't > stuffed up somewhere, all will be okay - (btw, I haven't > had experience > using mysql, but I'm assuming that it's sql is compatable > with interbase and > oracle) > > Hope that helps > Martin > > -Original Message- > From: Brian Tully [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 10, 2002 8:59 AM > To: PHP DB; PHP > Subject: [PHP] need help looping through each record with > a query - > stumped > > > hey folks - > > i'm stumped. been working on what i thought would be a > simple script to > cycle through users' records and perform a query. But I > can't get the loops > right, it seems like only one or two records get updated. > > Using MySQL, we have about 2000 students enrolled. each > month they take a > test. if they pass the most recent 3 tests > (consecutively) they earn > "Certified" status and get a few perks. > > Somehow the certification status' got messed up. So I'm > trying to create a > script that will look through each user's test records to > see if they've > passed the last 3 tests, and if so, change their > certification status in the > database. > > Not very elegant since there are so many records in the > database (2000 > users), but I don't think i have a choice. > > Anyways, I've tried to loop through each user, and for > each user loop > through their scores. But the loops aren't working. I'm > sure it's something > simple and obvious I'm missing but my brain is fried! > > I'd appreciate it if someone could take a look and offer > any advice. It's > about 65 lines of code (with comments). > > thanks in advance! > brian > > > > > include("/home/includes/.connect.inc"); > > // Select each Username and start a loop of queries for > each user > > $query = ("SELECT Username, Certification FROM users"); > > $result = mysql_query($query) > or die ("Cannot execute query" . mysql_error ()); > > /* > here starts the loop - for each user in the database we > look at their test > records and try to establish if they have passed the last > 3 tests > consecutively > */ > > while (list($Username, $Certification) = > mysql_fetch_row($result)) { > > $query2 = ("SELECT Month, Score FROM scores WHERE > Username = > '$Username'"); > > $result2 = mysql_query($query2) or die ("Cannot > execute query" . > mysql_error ()); > > > /* > for each score record the user has, check to see if > they've passed the last > 3 tests > */ > > while (list($Month, $Score) = > mysql_fetch_row($result2)) { > > > /* > here we initialize a counter which we'll use to tally how > many tests the > user has passed over the past 3 months > */ > > $tally = 0; > > if (($Month == 'January') && ($Score >= 75)) { > > $tally++; > } > > if (($Month == 'December') && ($Score >= 75)) { > > $tally++; > } > >
[PHP-DB] RE: [PHP] Help needed - need to access a value from DB into all pages
I can think of three ways you could do this. 1. as a cookie 2. using sessions 3. put it in every link Martin -Original Message- From: WG4- Cook, Janet [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 10:59 AM To: PHP db list; PHP List Subject: [PHP] Help needed - need to access a value from DB into all pages Hi there, I am struggling with a concept and can't seem to find a way to do it so hoping you all can help. We want to use PHP with MySql Db. For security reasons on the DB, it is to be accessed only through this front end i.e. via the internal web Each user will have a number of levels of access to various parts of the system, so the obvious design is one where there is only 1 real login to the MySQL db (i.e. the system will auto log everyone in as this without them knowing it), and then the user is validated against a table in my DB which holds the access rights. I can get through the login OK, and get my table to return "USERID" for this person. Now I need that "USERID" available to ALL other pages so I can use it to determine what parts of screens to show, and what to allow them to do. My question is how do I make this variable available to all pages?? Do I have to include it with the variables passed to each page or is there a simpler way of doing it. Can I put the variable in an include file and include it in every page - will that work?. Surely someone must have had a similar situation before and can tell me how they solved it. Many thanks Janet -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] RE: [PHP] How to Show my Own Error Message Instead of Mysql Error?
what about doing a "select count(*) from table where username = 'foobar'" then, if ($cnt > 0) { /* display error */ } else { /* insert new username */ } -Original Message- From: Jack [mailto:[EMAIL PROTECTED]] Sent: Friday, June 21, 2002 2:07 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP] How to Show my Own Error Message Instead of Mysql Error? Dear all i made a Registration Form for user to input their Data, but i also had some Field Check before the data can be insert to the Mysql_Database! I had a question here, sometime the mysql shows the error : "Duplicate Key for xxx" I know what is this about, reguarding to my Registration Form, it mean the Login Name is Duplicated! But i want to show my own message to the user for this error instead the Mysql Error! It is meanness to show User the Mysql Error, cause they won't understand it!!! Could Someone pls tell me how i can do this? -- Thx a lot! Jack [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] RE: [PHP] Hex Help Please...
Doesn't look like anyone has replied to you on the php-general mailing list. Have a look at this page http://www.wotsit.org/search.asp?s=graphics some of the docs there might help you HTH Martin -Original Message- From: Georgie Casey [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 6:16 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP] Hex Help Please... Rite, There's a PHP script that takes a monochrome BMP and converts it into some sort of hex code and I've noticed some patterns with this code. This image is 72 pixels wide by 14 high so there's 1008 pixels. In the code returned, theres 252 chars, which is 1008 divided by 4. So I guessed the image is split into 4 pixels each. So if I pass an image with the first pixel black and everyhting else white, it returns 8 for those 4. If I pass an image with the first and second black, it returns c. With the first three black, it returns e. With the first 4, f. And if I have the 5th pixel black it goes onto the next char code, eg returning f for the first 4 pixels, then 8 for the 5th pixel black, ie the first pixel in the next 4. In total it returns f8. PS I tried reading in each pixel of the script, checking if it was black or white, 1 for black, 0 for white. Then converting these 0s and 1s from decimal to hex, then converting from binary to hex, but to no avail. Then I tried taking a set of 4 1s or 0s and converting them, but still no luck. So my questions is, does anyone know how theyre encoding the image I could probably could decipher the coding with some experimentation but it really looks like hex and I might be wasting my time. TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php