PDA

View Full Version : Using a while statement in an echo.



Excellent1
28-08-2008, 08:19 PM
Not done this before but is it possible? Say if you wanted to show some select options from a specific table in your database, could you do it like this?


$query = mysql_query("SELECT * FROM `tablename` WHERE `selects`");
echo ("<form method='post' action='blahhhh'>
Selects:<br>
<select name='select' size='1'>
<option selected>Select one</select>
while ($cat = mysql_fetch_array($query)) {
<option value='$select[id]'>$select[name]</option>
}
</form>");Probably confusing to some but would appreciate the advice :)

Closed by Invent (Forum Moderator): Thread closed due to prevent further arguments and going off-topic.

Dentafrice
28-08-2008, 08:23 PM
Hell no.

Number one, echo isn't a function.. drop the ()'s.

And why do you have WHERE `selects`, what is selects?

Delatory
28-08-2008, 08:24 PM
Nope that wouldn't work, If you did try that it wouldn't do the script it would just send it to the page.



$query = mysql_query("SELECT * FROM `tablename` WHERE `selects`");
echo ("<form method='post' action='blahhhh'>
Selects:<br>
<select name='select' size='1'>
<option selected>Select one</select>");
while ($select = mysql_fetch_array($query)) {
echo ("<option value='$select[id]'>$select[name]</option>");
}
echo ("</form>");


You'd have to stop the echo, do the query then have to echo the last bit of the form. It also wouldn't work with having $cat = mysql_fetch_array and then using $select ;)

And fix the query

Dentafrice
28-08-2008, 08:25 PM
Nope that wouldn't work, If you did try that it wouldn't do the script it would just send it to the page.



$query = mysql_query("SELECT * FROM `tablename` WHERE `selects`");
echo ("<form method='post' action='blahhhh'>
Selects:<br>
<select name='select' size='1'>
<option selected>Select one</select>");
while ($select = mysql_fetch_array($query)) {
echo ("<option value='$select[id]'>$select[name]</option>");
}
echo ("</form>");


You'd have to stop the echo, do the query then have to echo the last bit of the form. It also wouldn't work with having $cat = mysql_fetch_array and then using $select ;)

And fix the query
Again, drop the ()'s, it is not a ******* function.

Also, for christ sakes, quit missing 's/"s on your variables.

It's $select["id"] and $select["name"], not $select[id], $select[name].

Excellent1
28-08-2008, 08:33 PM
Hell no.

Number one, echo isn't a function.. drop the ()'s.

And why do you have WHERE `selects`, what is selects?
Oops, my bad! I had a silly thought about a table in the table, lol.


Nope that wouldn't work, If you did try that it wouldn't do the script it would just send it to the page.



$query = mysql_query("SELECT * FROM `tablename` WHERE `selects`");
echo ("<form method='post' action='blahhhh'>
Selects:<br>
<select name='select' size='1'>
<option selected>Select one</select>");
while ($select = mysql_fetch_array($query)) {
echo ("<option value='$select[id]'>$select[name]</option>");
}
echo ("</form>");
You'd have to stop the echo, do the query then have to echo the last bit of the form. It also wouldn't work with having $cat = mysql_fetch_array and then using $select ;)

And fix the query
Yeah, that was the way I was going to do it, just didn't know if it could be done another way :) +REP though.
At denta, I use 's on personal scripts only, I use correct terms on client work.

Dentafrice
28-08-2008, 08:36 PM
Well I really don't see how you could have client work with coding like this, and asking a question like this.

If you can't figure this out, how could you figure something 20x more complex out.. that doesn't have to do with echos :\

If you can't experiment and try things yourself, before asking.. then you shouldn't be asking at all.

MrCraig
28-08-2008, 08:45 PM
need to close the </select> tag still..

and i use echo(" "); too, just a habbit lol ;p

Excellent1
28-08-2008, 08:52 PM
Well I really don't see how you could have client work with coding like this, and asking a question like this.

If you can't figure this out, how could you figure something 20x more complex out.. that doesn't have to do with echos :\

If you can't experiment and try things yourself, before asking.. then you shouldn't be asking at all.Read what I said above, my coding is not clean when I'm doing it for myself, client coding is clean and uses proper terms and syntax. Secondly I don't have access to my servers at the moment so I can't test out the outcome can I?


need to close the </select> tag still..

and i use echo(" "); too, just a habbit lol ;pYeah, I knew the proper way, just thought there may be another way :) Haha, (" ") is a bad bad habit I'm sure a lot of coders share :P

kreechin
28-08-2008, 10:44 PM
Yeah same I've been usingg echo (" "); since I started coding, picked it up off Naresh's user system I think, so I assumed it was correct, although i do use " "; now and again when i'm in a rush to throw something together.

Dentafrice
28-08-2008, 11:21 PM
""; and ''; are the proper ways, no use to make it into a method.

Naresh's user system was badly coded, as he now admits ;P

Excellent1
29-08-2008, 12:03 AM
""; and ''; are the proper ways, no use to make it into a method.

Naresh's user system was badly coded, as he now admits ;P
You could use ''; aswell but ""; is the proper solution. Naresh's usersystem was badly coded as you said but it set the tone for a few PHP coders today :)

Dentafrice
29-08-2008, 12:06 AM
I just said ''; and "";, you don't need to tell me what are the "proper solutions", I believe I know a tad bit more then you ;)

Agnostic Bear
29-08-2008, 02:52 AM
I just said ''; and "";, you don't need to tell me what are the "proper solutions", I believe I know a tad bit more then you ;)

And I believe I know a "tad bit" more than you, no need to boast now, and using either ("") / ('') or '' / "" is correct, it's just what you use for your coding style, i don't use () on return ''; but I use it on echo(); It's just a personal choice, there are no rights or wrongs here.

Hypertext
29-08-2008, 03:46 AM
Read what I said above, my coding is not clean when I'm doing it for myself, client coding is clean and uses proper terms and syntax. Secondly I don't have access to my servers at the moment so I can't test out the outcome can I?

Yeah, I knew the proper way, just thought there may be another way :) Haha, (" ") is a bad bad habit I'm sure a lot of coders share :P

Sorry, but to have a client, and code like that, even without testing, is impossible... unless your client is seriously mentally impaired.

Oh, and I've said this a million times, using parenthesis on language constructs DOES slow the script down.

Also a quick clarification for a lot of people who don't seem to understand the difference between '' and "", the MAIN difference (not the only) is that using double quotes you can have variables inside it.

Example



echo "$hello"; //works
echo '$hello'; // doesnt work

echo "hello"; //works
echo 'hello'; // also works and is a lot faster

Protege
29-08-2008, 05:28 AM
I use
echo( 'Pls ***' );

cuz its me personal choice yo yo & looks well sxi lyk mr sxi bear xoxox

redtom
29-08-2008, 09:28 AM
Secondly I don't have access to my servers at the moment so I can't test out the outcome can I?


Xampp (http://www.apachefriends.org/en/xampp-windows.html#646) :)

Source
29-08-2008, 10:58 AM
And I believe I know a "tad bit" more than you, no need to boast now, and using either ("") / ('') or '' / "" is correct, it's just what you use for your coding style, i don't use () on return ''; but I use it on echo(); It's just a personal choice, there are no rights or wrongs here.

*Removed*. "Blah" and 'Blah' are the proper ways, I just asked the other developers @ work - they have qualifications in most languages and I'm sure they would know the best way... ('') works, but it looks naff.

Anyhoo, just do a while statement with an echo in it.... rather than the while in an echo as that is just not possible..


Edited by ,Jess, (Forum Super Moderator): Please do not be rude towards other forum members.

Agnostic Bear
29-08-2008, 11:34 AM
You are the biggest **** on this forum, end of story. "Blah" and 'Blah' are the proper ways, I just asked the other developers @ work - they have qualifications in most languages and I'm sure they would know the best way... ('') works, but it looks naff.
So you're flaming me for saying exactly what they said before you asked them?

Well done.

Stepheen
29-08-2008, 11:38 AM
You are the biggest **** on this forum, end of story. "Blah" and 'Blah' are the proper ways, I just asked the other developers @ work - they have qualifications in most languages and I'm sure they would know the best way... ('') works, but it looks naff.

Anyhoo, just do a while statement with an echo in it.... rather than the while in an echo as that is just not possible..
Can you take a photo of them?

Excellent1
29-08-2008, 11:40 AM
I just said ''; and "";, you don't need to tell me what are the "proper solutions", I believe I know a tad bit more then you ;)And I believe you should calm the attitude, pull that head from your rear and get off the high horse back onto the playground pony.

Hypertext
29-08-2008, 11:57 AM
Umm. Jewbear told you the right thing if your excuse if they 'look good' then umm.... fail.

Calon
29-08-2008, 11:59 AM
Sorry, but to have a client, and code like that, even without testing, is impossible... unless your client is seriously mentally impaired.

Oh, and I've said this a million times, using parenthesis on language constructs DOES slow the script down.

Also a quick clarification for a lot of people who don't seem to understand the difference between '' and "", the MAIN difference (not the only) is that using double quotes you can have variables inside it.

Example



echo "$hello"; //works
echo '$hello'; // doesnt work

echo "hello"; //works
echo 'hello'; // also works and is a lot faster

I've actually said that to him before. (Excellent1)

echo '$hello'; // doesnt work

Hypertext
29-08-2008, 12:47 PM
I've actually said that to him before. (Excellent1)
He doesn't seem to listen, same with Protege.

Excellent1
29-08-2008, 02:58 PM
He doesn't seem to listen, same with Protege.Charlie you wouldn't know anything about parenthesis without the your PHP For Kids e-book.

Dentafrice
29-08-2008, 05:20 PM
And I believe you should calm the attitude, pull that head from your rear and get off the high horse back onto the playground pony.

Oh, I'm sorry Mr. Professional, your clients might see me :rolleyes:.


Charlie you wouldn't know anything about parenthesis without the your PHP For Kids e-book.

And I believe you should calm the attitude, pull that head from your rear and get off the high horse back onto the playground pony.

Seems to work in this situation also.

Excellent1
29-08-2008, 06:17 PM
Oh, I'm sorry Mr. Professional, your clients might see me :rolleyes:.[quote]First of all, fail. Learn to construct a decent enough comeback that could somewhat enable me to react next time ;)



And I believe you should calm the attitude, pull that head from your rear and get off the high horse back onto the playground pony.

Seems to work in this situation also.I have no attitude, the only reason you're using what I said is to try get back at me somehow. Any other thread you would be boasting about how rubbish charlie is at PHP, professionalism dentafrice - get some.

Dentafrice
29-08-2008, 06:26 PM
This is quite funny, you're telling me to be professional, yet you're being quite the hypocrite with this comment:


Charlie you wouldn't know anything about parenthesis without the your PHP For Kids e-book.

That seems very professional. If you are quite the 'professional' one, then why are you going around making comments like that?

Because you're not professional, so you can't stand in a place telling me to "get some professionalism."

Professionalism is not something you can get.. it's not an object, it is just a subterm of professional.

Quit acting like your an adult, I'm sorry you're still 15.

Calon
29-08-2008, 06:27 PM
Oh, I'm sorry Mr. Professional, your clients might see me :rolleyes:.



And I believe you should calm the attitude, pull that head from your rear and get off the high horse back onto the playground pony.

Seems to work in this situation also.
I agree.

Lucas -Who are you clients? *OH WAIT, PRIVACY!*

Dentafrice
29-08-2008, 06:29 PM
I agree.

Lucas -Who are you clients? *OH WAIT, PRIVACY!*
Lucas having clients? You mean his mom and dad's homemade toothpaste business.. :rolleyes:

Source
29-08-2008, 06:31 PM
Salty Fresh :)

I find it hard for anyone to act anywhere near professional on a habbo forum. Anyhoo why does it matter.

Calon
29-08-2008, 06:35 PM
Lucas having clients? You mean his mom and dad's homemade toothpaste business.. :rolleyes:
LOL

That was a bit random? And yeah, I doubt he's actually ever had any clients. Because his coding is terrible, fair play for him trying to neaten it but he uses echo( '$string' ) etc, and I don't think you can even do that. If that's how he echo's a variable, then his clients are blatently visually impaired.

Dentafrice
29-08-2008, 06:38 PM
<?php
echo $variable;
?>


Not that hard...



<?php
echo "Hello {$username}, welcome.";
?>

Excellent1
29-08-2008, 06:51 PM
This is quite funny, you're telling me to be professional, yet you're being quite the hypocrite with this comment:



That seems very professional. If you are quite the 'professional' one, then why are you going around making comments like that?

Because you're not professional, so you can't stand in a place telling me to "get some professionalism."

Professionalism is not something you can get.. it's not an object, it is just a subterm of professional.

Quit acting like your an adult, I'm sorry you're still 15.
Thats the truth, I'm sure you would agree charlie has got all this parenthesis language from books or people he's bugged/sucked up to in the past (you and others).


I agree.

Lucas -Who are you clients? *OH WAIT, PRIVACY!*
My clients? WOWTech, Lou (on this forum) Got payed £100.00 for a video gallery system (ask RWhost).


Lucas having clients? You mean his mom and dad's homemade toothpaste business.. :rolleyes:Again you're what, 17-18 but you're acting like a 12 year old.


LOL

That was a bit random? And yeah, I doubt he's actually ever had any clients. Because his coding is terrible, fair play for him trying to neaten it but he uses echo( '$string' ) etc, and I don't think you can even do that. If that's how he echo's a variable, then his clients are blatently visually impaired.Read above.




<?php
echo $variable;
?>
Not that hard...



<?php
echo "Hello {$username}, welcome.";
?>

It's personal preference for personal work.

Dentafrice
29-08-2008, 06:59 PM
Thats the truth, I'm sure you would agree charlie has got all this parenthesis language from books or people he's bugged/sucked up to in the past (you and others).


It doesn't matter if that's what you think, you are implying you are professional.. and that's not a professional comment.

Hypocrite.




My clients? WOWTech, Lou (on this forum) Got payed £100.00 for a video gallery system (ask RWhost).

If they saw some real coding, they sure as hell would not have chosen you.

Congrats, you got £100! I get triple that for framing and drywalling a 10'x10' room.


Again you're what, 17-18 but you're acting like a 12 year old.

Congratulations.. a child's opinion like yours isn't really going to bother me..


It's personal preference for personal work.

That's right, but if you're going to post personal work on a forum.. then for god sakes, don't make it look like ****.. and don't make it be a stupid question if you're so 'great'.

Look.. that code was ******* awful, it was a stupid question.. which any 'decent' coder would know.. you're still learning.. states away from being near professional.

So if you're going to make awful preferences for your 'personal work', then keep your 'personal work', personal.. and don't ask questions on the forum with awful code.

Excellent1
29-08-2008, 07:05 PM
It doesn't matter if that's what you think, you are implying you are professional.. and that's not a professional comment.

Hypocrite.
I am in no way a professional, I do minor work for people who are paying, simple as.


If they saw some real coding, they sure as hell would not have chosen you.
What part do you not get, the only code you have seen from me is scrappy personal work which I don't give a toss about and want to spend as little time as possible working on.


Congrats, you got £100! I get triple that for framing and drywalling a 10'x10' room.
I've been learning php for 3-4 months now, I'd say thats good for a beginner but I'm sure you'd beg to differ.


Congratulations.. a child's opinion like yours isn't really going to bother me..Child? Hypocrite.



That's right, but if you're going to post personal work on a forum.. then for god sakes, don't make it look like ****.. and don't make it be a stupid question if you're so 'great'.

Look.. that code was ******* awful, it was a stupid question.. which any 'decent' coder would know.. you're still learning.. states away from being near professional.

So if you're going to make awful preferences for your 'personal work', then keep your 'personal work', personal.. and don't ask questions on the forum with awful code.I agree the code was horrible but I cannot be bothered making my own work clean when all I need is it to work for ME. I agree the code was crap and the question was silly but if you don't ask you don't get, I am new to php, I bet when you was new to the language you asked some pretty stupid questions you would sit back on today and laugh about.

Dentafrice
29-08-2008, 07:11 PM
I am in no way a professional, I do minor work for people who are paying, simple as.

Well you're telling me I need to 'get some professionalism', which implies that you think you are a professional.



What part do you not get, the only code you have seen from me is scrappy personal work which I don't give a toss about and want to spend as little time as possible working on.

Still, you're presenting it to the public for a question, so it should at least use some decent methods.



I've been learning php for 3-4 months now, I'd say thats good for a beginner but I'm sure you'd beg to differ.

I know people that have been coding for 3-4 months now, and have a fully working, safe, and effective system, and are developing use OOP and efficient programming methods.

One example would be Source, and Source-Movies. ;) So you're a little behind for 3-4 months.



Child? Hypocrite.

I'm by far not a child ;) I already have an Associates Degree in CS, and in another year I'll have my Bachelors Degree in CS. I've also got a Sub Associates Degree in Computer Programming and I'm working on Marketing as another sub.

I'm by far not a child ;)



I agree the code was horrible but I cannot be bothered making my own work clean when all I need is it to work for ME. I agree the code was crap and the question was silly but if you don't ask you don't get, I am new to php, I bet when you was new to the language you asked some pretty stupid questions you would sit back on today and laugh about.

Then don't post it, if you want us to take you seriously.. don't post **** code and then agree it's ****.. you're posting asking us for help, so present yourself well, that makes us want to help you.. and makes us believe you want to learn.

You shouldn't code that horrible for yourself anyway, just wait until you actually make something.

Yeah, I asked stupid questions, but I presented myself well, and didn't say the 'code was horrible, but it is for me..', I said the code was horrible because I didn't know.. and I asked for ways to fix it.

Not like you're doing.

Hypertext
29-08-2008, 11:37 PM
Excellent, stop being bitter.

And I'd second Dentafrice's comment. 3-4 months and you still use parenthesis in language constructs, umm... quit?

Agnostic Bear
30-08-2008, 12:38 AM
Excellent, stop being bitter.

And I'd second Dentafrice's comment. 3-4 months and you still use parenthesis in language constructs, umm... quit?

I use parenthesis on some language constructs, are you telling me to quit as well? :rolleyes:

Hypertext
30-08-2008, 02:06 AM
Depending on which ones, probably.

Dentafrice
30-08-2008, 03:08 AM
Excellent, stop being bitter.

And I'd second Dentafrice's comment. 3-4 months and you still use parenthesis in language constructs, umm... quit?

Yeah, and with Dan, years.. and he is still doing it.

It's even recommended on the PHP.net site, that you don't use ()'s with language constructs, as it gives PHP more work to do.

It was suggested that using ()'s with language constructs be removed in 6.0, and is still an undecided issue.

Agnostic Bear
30-08-2008, 03:33 AM
Yeah, and with Dan, years.. and he is still doing it.

It's even recommended on the PHP.net site, that you don't use ()'s with language constructs, as it gives PHP more work to do.

It was suggested that using ()'s with language constructs be removed in 6.0, and is still an undecided issue.

What, where are you getting this information, using parenthesis doesn't make it do any extra work at all.

Dentafrice
30-08-2008, 03:49 AM
Note: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.


Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a).

;).....

Agnostic Bear
30-08-2008, 04:05 AM
;).....

Did you not see the part where it says "in this case" and where I say "I don't use parenthesis on return"???

Dentafrice
30-08-2008, 04:07 AM
Yeah, it's for echo too.. I can't find it tonight.

Either way the core still has to process it like a function, and it has it's limitations, and slows it down by a moderate degree.

Agnostic Bear
30-08-2008, 06:06 AM
Yeah, it's for echo too.. I can't find it tonight.

Either way the core still has to process it like a function, and it has it's limitations, and slows it down by a moderate degree.

I don't think so :)

Dentafrice
30-08-2008, 11:53 AM
Read up on how the core actually works, you'll see how it goes at parsing languages constructs, using ()'s does give it more work.. because it has to sort through them, plus make sure not more then one variable is in it.

Want to hide these adverts? Register an account for free!