Jump to content

odisey

Members
  • Posts

    66
  • Joined

  • Last visited

    Never

Everything posted by odisey

  1. Thanks guys. This is an excellent forum! I have the array() lesson. You guys should LOCK that upTop. Odisey
  2. mbeals I got it! with this: if ($result) { $i=1; while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { $varname = "vars$i"; //will create a variable name: var1, var2, var3.... $i++; $$varname = $row[0]; } //echo "$vars1 $vars2 $vars3"; } echo '<p>'. $vars1 . '</p>'; echo '<p>'. $vars2 . '</p>'; echo '<p>'. $vars3 . '</p>'; I am interested in what Crayon Violet thinks about passing these variables to flash as file names for swf movies to load. Does this make sense -- will it work? TY for your help guys, I am getting there. Odisey
  3. In response to Crayon violet: This is excellent. It is just over my head at this time. Trying to learn here. I had had a LIMIT 3 in an earlier version. And decided it was not needed until I had defined the unique variables. Here is what I want to do with the data. You said you are not sure why I want unique variables when they contain the same information. This is one of my disconnects with learning Php. It seems if you can create an array with many variables, you should be able to deconstruct it as well and then use each. I am missing this...I just can't wrap the brain around it. I want to stay within a mental framework that is comprehensible to me.... Otherwise I might get something that works, I won't know why it works though. I want to send three randomly chosen variables to flash. Of course these are derived of the images column in the db. There are eight images total. These will be swf file names once I get this code figured out. As you can imagine I want to load those randomly choosen file (swfs) in Flash once they are passed. I am much better on Php that AS. Arrays make me crazy. How to make them, use them for drop downs, etc... np. I just want to access the array in Php and create unique varialbes ($vars1, $vars2, $vars3...etc...)...so I can see it with my own two eyeballs. This way the how why what where may finally enter my brainstem and take up residence. If I can do this GREAT! I am reading the AS Bible and I have a Joey Lott course I am taking. More complicated AS will come soon. TY I will save this code. Is it possable to create these unique variables in Php? What concepts about arrays am I completely missing here? TY Odisey OK: Let me try to rework mbeals version TY. I though the double $$ was a typo. Almost there.
  4. No I cannot get it. More help needed. What have I right and wrong here?
  5. I am getting closer, I can feel it. Here is what I am testing, and it is not working. Once I see the syntax in proper fashion, I will understand the logic. BE RIGHT BACK <?php #Color instrument vars # ODC August 4, 2008 require_once ('????.php'); //Connect to database RESET TO SAFE PATH ONCE IT FUNCTIONS // Define variables $var1 = "Hello"; // Make selection $query = "SELECT images FROM movie_images ORDER BY RAND()"; $result = mysql_query($query) or die(mysql_error()); // Table if ($result) { $i=1; while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { $varname = "vars$i"; //will create a variable name: var1, var2, var3.....varn $i++; $varname = $row[0]; ####### ##or use an array if you can $vars[] = $row[0]; } echo '<p>'. $var1 . '</p>'; //echo '<p>'. $result . '</p>'; //echo '<p>'. $s3 . '</p>'; echo '<p>'. $vars2 . '</p>'; } else { echo 'There was a problem...'; } mysql_close(); // Close database connection ?>
  6. Yeah, this is what has eluded me. I think this is the answer. I will try this out and get back in a few minutes. TY! Odisey
  7. I read your post, and I really am not sure what the problem is by what you have said. You do not what something selected duplicated? Can you be more specific? I will try. Odisey
  8. Hello freaks! I am trying to do something that seems so simple, yet a day later I resort to your expertise. I am selecting all rows in a column in a MySQL db. There are 8 records. I want to sort them ramdomly and pluck the top three. I don't just want to loop and print the results, I want to redefine each as a unique variable to pass to Flash. The code I have here will print the results. How do I reassign the results to unique variables? Thank you for your help. Odisey <?php #Color instrument vars # ODC August 4, 2008 require_once ('???????????.php'); //Connect to database RESET TO SAFE PATH ONCE IT FUNCTIONS // Define variables $var1 = "Hello"; // Make selection $query = "SELECT images FROM movie_images ORDER BY RAND()"; $result = mysql_query($query) or die(mysql_error()); // Table if ($result) { while ($row = mysql_fetch_array ($result, MYSQL_NUM)) { $s1 = $row[0]; // $s2 = $row[1]; // $s3 = $row[2]; echo '<p>'. $s1 . '</p>'; //echo '<p>'. $result . '</p>'; //echo '<p>'. $s3 . '</p>'; echo '<p>'. $var1 . '</p>'; } } else { echo 'There was a problem...'; } mysql_close(); // Close database connection ?>
  9. Can you explain in a little more detail what you mean? Do you mean results returned from a query to a MySQL db using php? I think you are using php because you are in the php forum. This is a php specific problem - if you are talking about the front end. In this case you have to code a function that dynamically writes the html code, adding your returned results to a list of hyperlinks. The hymperlinks again would point to a page which provided the more comprehensive information you want to display. Unless someone else chimes in with a predefined function php may have that displays infomation (such as the php info function - which displays version and settings), I think you will have to actually code it. Marc
  10. I've narrowed it down to the SELECT statement dot syntax. Why would dot syntax execute in the WHERE statement and not the SELECT statement? This will not execute: $query = "SELECT student_score.description_id, student.last_name WHERE student_score.mid_final = 'M' AND student_score.student_id = 700900127 AND student_score.year = 2006 AND student.student_id = 700900127"; This will $query = "SELECT description_id FROM student_score WHERE student_score.mid_final = 'M' AND student_score.student_id = 700900127 AND student_score.year = 2006"; Marc
  11. I had tried that - and again after your post... Nothing prints...?
  12. I am trying this simple snippet to get a print to build from -- I get nothing... Any ideas why? $query = "SELECT student.last_name, characteristics.char_desc WHERE student_score.mid_final = 'M' AND student_score.student_id = '700900127' AND student_score.year = '2006'"; /* , SUM (student_score.score) as total FROM student_score INNER JOIN question ON student_score.q_id = question.q_id INNER JOIN area ON question.area_id = area.area_id INNER JOIN characteristics ON area.char_id = characteristics.char_id INNER JOIN student ON student_score.student_id = student.student_id GROUP BY student.last_name, characteristics.char_desc"; */ $result = @mysql_query($query); if ($result) { echo 'result'; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { /* echo '<p align="left">' . $row['total'] . '</p>'; // ' . $row['char_desc']'</p>'; echo '<br /><br />'; */ echo "<pre>"; print_r($row); echo "</pre>"; } } Thank you for all your help, Marc
  13. Actually Barand helped me construct the tables and joins...expert. I have the site built now...And I am adding the last page...the print results pages(s). Thank you, Marc
  14. Id is possable to get an example of the query and output?
  15. I am not sure if this is the right forum: My question is about running a db parse query. Using PhpMyAdmin I would run something like: SELECT student.studentname, characteristics.char_desc, SUM(student_score.score) as total FROM student_score INNER JOIN question ON student_score.q_id = question.q_id INNER JOIN area ON question.area_id = area.area_id INNER JOIN characteristics ON area.char_id = characteristics.char_id INNER JOIN student ON student_score.student_id = student.student_id WHERE student_score.mid_final = 'M' AND student_score.student_id = '7001234' AND student_score.year = '2006' GROUP BY student.studentname, characteristics.char_desc Notice I have accessed columns in two tables, student and characteristics. Is it possable to run such a query in Php to parse a MySQL db? Something like $query = "SELECT column FROM table1 AND column FROM table2, SUM SUM (student_score.score) as total FROM student_score INNER JOIN question ON student_score.q_id = question.q_id INNER JOIN area ON question.area_id = area.area_id INNER JOIN characteristics ON area.char_id = characteristics.char_id INNER JOIN student ON student_score.student_id = student.student_id WHERE student_score.mid_final = 'M' AND student_score.student_id = '7001234' AND student_score.year = '2006' GROUP BY student.studentname, characteristics.char_desc"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { PRINT HERE
  16. I'm considering this. I already coded a page of 45 questions with multiple checks, etc... it is 7000 lines of code. I need to add one more check to the lot...I got it installed and it works. I just lost functionality of the inner most if statement. I will re-evaluate the structure again .. looks like it should execute. I found the Power's statement. Actually he said you can embed as many blocks of PHP into xhtml as you like ... just don't nest them. I mis-remembered-intrepreted-read what I read. OK - Thank you for the feedback
  17. I am reading David Power's PHP Solutions and I am absolutely sure he stated "You can use as many if else statements as you like, just don't nest them. I am looking for the page to re-read it as I though this is the problem I am having with a block of code. So...other nested blocks I have, and example I have are nested...I am not sure why he said that..maybe I misread. I am looking for it again... Marc
  18. Hello, I am wondering about conditional structures and the depth of nesting allowed, if at all. For example I know I can do this: If () { if () { Do this } else { Do this } } else { Do this } } Is this OK to do? If yes, how deep can one go ? Marc
  19. Thanks for at least looking at the post.... I've finally solved it 98%,,, one small glitch I should fix. Code that works for any that are interested: //BEGIN RECORD ENTRY 2 // Test for duplicate record. if ($sc2 != 'n') { // Check for score submission // Check for NAs -------------------------------------------------- if ($de2 == '1') { // Begin check for NAs $query = "SELECT description_id FROM student_score WHERE description_id=1 AND year='$ye' AND student_id='$s_id'"; $result2na = mysql_query($query); if (mysql_num_rows($result2na) >= 3) { // If 3 or less NAs. OPEN 3 Nest 2 echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. There is a limit of 3 Not Applicable evaluations for a student during a given year. <b> This student has three for ' . $ye . ' already.</b> Please modify your evaluation form.</font></p>'; } else { /// Check for NAs --------------------------------------------------- $query = "SELECT student_id FROM student_score WHERE q_id = '$qu2' AND year = '$ye' AND mid_final = '$mf' AND student_id = '$s_id'"; $result1 = mysql_query($query); if (mysql_num_rows($result1) == 0) { // If no duplicate record add the new record. OPEN 2 Nest 1 $query = "INSERT INTO student_score (q_id, student_id, year, mid_final, score, description_id) VALUES ('$qu2', '$s_id', '$ye', '$mf', '$sc2', '$de2')"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. OPEN 4 Nest 3 //Print message echo '<p><h3>Record question 1.1.2 was inserted.</h3></p>'; } } } // END RECORD ENTRY } // Close NA check else { // If it did not run OK //Print message echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. Record exists in data bank - use student edit page to alter this record.</font></p>'; } } // Close last IF
  20. I've modified this code. There are two parts here. In the first code section is the working code to insert a new record. In the second is the part I would like to add to the first - a check for number of NAs. I cannot integrate it for some reason.... help is appreciated. //BEGIN RECORD ENTRY 2 // Test for duplicate record. if ($sc2 != 'n') { // BEGIN IF OPEN 1 $query = "SELECT student_id FROM student_score WHERE q_id = '$qu2' AND year = '$ye' AND mid_final = '$mf' AND student_id = '$s_id'"; $result1 = mysql_query($query); if (mysql_num_rows($result1) == 0) { // If no duplicate record add the new record. OPEN 2 Nest 1 $query = "INSERT INTO student_score (q_id, student_id, year, mid_final, score, description_id) VALUES ('$qu2', '$s_id', '$ye', '$mf', '$sc2', '$de2')"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. OPEN 4 Nest 3 //Print message echo '<p><h3>Record question 1.1.2 was inserted.</h3></p>'; } } else { // If it did not run OK - more than 3 NAs OPEN 5 Nest 3 //Print message echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. Record exists in data bank - use student edit page to alter this record.</font></p>'; } } // END RECORD ENTRY // Test for # NAs. $query = "SELECT description_id FROM student_score WHERE description_id=1 AND year = '$ye' AND student_id = '$s_id'"; $result2na = mysql_query($query); if (mysql_num_rows($result2na) <= 3) { // If 3 or less NAs. OPEN 3 Nest 2 echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. There is a limit of 3 Not Applicable evaluations for a student during a given year. <b> This student has three for ' . $ye . ' already.</b> Please modify your evaluation form.</font></p>'; }
  21. I think this is somewhat accurate -- please add to this description if I am not accurate, I am very new to this.... When you create a function you may create unique variables in the function which have a scope of that function only - they are limited to that function only. For example if function 1 has a variable named $variable1 and function 2 has a variable named $variable1 - both of the $variable1s I just described are different variables even though they have the same name. Now if we start over and you use a predefined or declaired global variable named $variable1, that means that now they are the same variable. I think for the utility you describe you need not worry about the server. If you think about a page of script as the entire world of that script - local variables only (I mean only variables on the script page I am talking about) - a global variable is the SAME variable on the entire page, no matter where it is. Non-globals are limited in scope or confined to their functions unless otherwise defined. I think. Marc
  22. Here I have a snippet of code. It is part of a form which sends it variable values of question number, score, score description. One of the score options is NA (Not Applicable). It has a score of "0" and a score description of "1." The are 45 questions consturucted like this code. I am coding a check into this code. It checks for the number of NAs already in the db. There can be a total of 3 or less for the year. I am checking each question individually as the db is populated. This way if questions 1, 2, 3, and 4 are all selected as NA on the submit - questions 1,2,3 will go to the db and 4 will return the error "A limit of 3 NAs." $sc1 = score for question 1. $de1 = score description for question 1. As you can see I am runnning a query and checking for the number of description_ids that = 1. This is the count on NAs in the db. In this example if three NAs are entered and the user TRIES to enter a 4th NA the error returns accurately. The problem is this. If the user TRIES to enter a different score other than NA (Proficient for example - which has a score of 3 and a score description or description_id of 4) the NA error is ALWAYS returned, and not the accurate error of Record question 1.1.2 was not inserted. Record exists in data bank - use student edit page to alter this record. Last - if this question has never before been entered -- it does enter accurately and the return message Record question 1.1.2 was inserted does print. // Test for duplicate record. if ($sc2 != 'n') { $query = "SELECT student_id FROM student_score WHERE q_id = '$qu2' AND year = '$ye' AND mid_final = '$mf' AND student_id = '$s_id'"; $result1 = mysql_query($query); if (mysql_num_rows($result1) == 0) { // If no duplicate record add the new record. // Test for # NAs. $query = "SELECT description_id FROM student_score WHERE description_id=1 AND year = '$ye' AND student_id = '$s_id'"; $result2na = mysql_query($query); if (mysql_num_rows($result2na) <= 3) { // If 3 or less NAs. $query = "INSERT INTO student_score (q_id, student_id, year, mid_final, score, description_id) VALUES ('$qu2', '$s_id', '$ye', '$mf', '$sc2', '$de2')"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (mysql_affected_rows() == 1) { // If it ran OK. //Print message echo '<p><h3>Record question 1.1.2 was inserted.</h3></p>'; } } else { // If it did not run OK - duplicate record exists. //Print message echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. Record exists in data bank - use student edit page to alter this record.</font></p>'; } } else { echo '<p class="error"><font color="red">Record question 1.1.2 was not inserted. There is a limit of 3 Not Applicable evaluations for a student during a given year. <b> This student has three for ' . $ye . ' already.</b> Please modify your evaluation form.</font></p>'; } } // END RECORD ENTRY I been working on this site for days.... Any help here is welcome, appreciated... Marc
  23. Good to know... I have one connection only ... so it must close on its own.... Thank you for the feedback! And from the manuel! Marc
  24. What is the significance of mysql_close(); ? Is it important to always close the db?
×
×
  • 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.