How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Matthew Gill Your Own Question

Matthew Gill
Matthew Gill, Programming Tutor
Category: Programming
Satisfied Customers: 17
Experience:  I have over 5 years experience as a Teaching Assistant for 15 programming courses at a 4-year university.
74898053
Type Your Programming Question Here...
Matthew Gill is online now
A new question is answered every 9 seconds

I am having problems with my while loop it is only running

Customer Question

I am having problems with my while loop it is only running the mysql function code once. Since num equals 3 should go through 3 times. please see attached file.


 


 


http://wikisend.com/download/579462/loopjustanswer.docx

Submitted: 1 year ago.
Category: Programming
Expert:  Martin replied 1 year ago.

Martin :

Hello, welcome to JustAnswer my name is XXXXX XXXXX I'm one of the experts who will be assisting you today.

There doesn't seem to be any PHP experts online at the moment but I have experience with other languages and would like to suggest something if that's ok with you?

Martin :

What would happen if you tried storing num with double quotes " " instead of single quotes or no quotes at all? Does that change anything for you?

Customer:

I think i stated the question wrong. It is going thru 3 times but the mysql_query($query1) or die ('Error saving Daily record'); function is only running one time

Customer:

I put the echo in and I see it printing to to screen 3 times.

Martin :

Oh ok so the loop works fine

Martin :

So it mustn't be evaluating the mysql query

Martin :

I will opt out and see if we can find you someone that knows mysql

Customer:

ok thanks

Expert:  Russell H. replied 1 year ago.
Do you just need to go through the loop three times? If so, why not use a MySQL
LOOP
statement/function, rather than a
WHILE
? see http://dev.mysql.com/doc/refman/5.5/en/loop.html

so that your code block would become something like this:

http://wikisend.com/download/474896/MySQL LOOP instead of WHILE.txt


If you'd rather have the WHILE statement patched up, or explained at least as to why it doesn't work, just let me know. But I think that what I offer is a practical answer to the problem.


- If there is anything lacking in this answer, please " Reply " letting me know, and I will try to improve upon my answer.
- If this is the Answer that helps with the issue, then rating my Answer positively would be appreciated.
Customer: replied 1 year ago.

the value of num will vary. Can I replace the number 3 in your answer with the variable num?

Expert:  Russell H. replied 1 year ago.
Yes, like

http://wikisend.com/download/362986/MySQL LOOP instead of WHILE with num.txt

num becomes the delimiter of how many times the loop iterates.

If it were some other programming code, of course, there might be a question of scope involved. Not in MySQL I don't think :)



- If there is anything lacking in this answer, please " Reply " letting me know, and I will try to improve upon my answer.
- If this is the Answer that helps with the issue, then rating my Answer positively would be appreciated.
Customer: replied 1 year ago.


i tried it but i got errors. I am using php and that procedure is not working

Expert:  Russell H. replied 1 year ago.
PHP and MySQL are quite different.

I had the impression that you were asking about a loop in MySQL coding, not in PHP; that accounts for the problems, I think.

Since I am not a PHP expert, I must Opt Out. Another Expert will take up the case by and by. Thanks.
Expert:  Matthew Gill replied 1 year ago.
Hello. My name is XXXXX XXXXX I'd like to help you with this problem. Could you please copy and paste your code into the reply window? I can better diagnose the problem this way. Thank you.
Expert:  Matthew Gill replied 1 year ago.
Disregard my previous request. I have downloaded the the document. I will get back with you momentarily
Expert:  Matthew Gill replied 1 year ago.
Place

$query1="UPDATE $TableName SET Attendance_Code='".$AC[$i]."' , Absence_Date='".$mydate."' WHERE Last_Name='".$LN[$i]."' AND First_Name='".$FN[$i]."'";

in the loop before the mysql_query() statement, and run the code. Please let me know if that works.
Matthew Gill, Programming Tutor
Category: Programming
Satisfied Customers: 17
Experience: I have over 5 years experience as a Teaching Assistant for 15 programming courses at a 4-year university.
Matthew Gill and other Programming Specialists are ready to help you
Customer: replied 1 year ago.


That worked. thanks for your help.

Expert:  Matthew Gill replied 1 year ago.
No problem. Do you understand why it wasn't working before?
Customer: replied 1 year ago.


I think it didn't work before because I defined the query outside the loop and when it went looped a second time the query1 was not declared so it just skipped it but I am not sure if this is the correct answer.

Expert:  Matthew Gill replied 1 year ago.
Your are partly correct. You did define the query outside the loop, as well as i and j. The first iteration of the loop (where i and j were 0) was correct, but because the query was not being updated in the loop, the values weren't changing. Essentially, the 'query1' value was set outside the loop, and that set value was used instead of the derived value you wanted. In other languages this wouldn't be such a big deal because you could use pointers. Good job!
Customer: replied 1 year ago.

THANKS FOR THE FOLLOW UP INFO. I REALLY APPRECIATE IT.

Expert:  Matthew Gill replied 1 year ago.
No problem! That's what it's about!!! Enjoy your day!

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
< Last | Next >
  • http://ww2.justanswer.com/uploads/SP/spatlanta2010/2011-6-23_12450_photo.64x64.gif ATLPROG's Avatar

    ATLPROG

    Computer Software Engineer

    Satisfied Customers:

    7463
    MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Computer Software Engineer

    Satisfied Customers:

    5603
    Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.
  • http://ww2.justanswer.com/uploads/unvadim/2010-11-15_210218_avatar.jpg unvadim's Avatar

    unvadim

    Computer Software Engineer

    Satisfied Customers:

    1158
    Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.
  • http://ww2.justanswer.com/uploads/lifesaver333/2010-10-17_191349_ls.jpeg lifesaver's Avatar

    lifesaver

    Computer Software Engineer

    Satisfied Customers:

    950
    Several years of intensive programming and application development experience in various platforms.
  • http://ww2.justanswer.com/uploads/EH/ehabtutor/2012-8-2_202016_1.64x64.jpg ehabtutor's Avatar

    ehabtutor

    Computer Software Engineer

    Satisfied Customers:

    864
    Bachelor of computer science, 5+ years experience in software development, software company owner
  • http://ww2.justanswer.com/uploads/RA/rajivsharma086/2012-6-6_17128_displaypic.64x64.jpg Raj's Avatar

    Raj

    Computer Engg.

    Satisfied Customers:

    860
    BE CS, 4+ Experience in Programming and Database (ERP)
  • http://ww2.justanswer.com/uploads/eljonis/2010-01-06_130406_eljon2.jpg Eljon's Avatar

    Eljon

    Consultant

    Satisfied Customers:

    590
    11 yrs of programming (PHP, WordPress, XSL, SQL, JavaScript)