Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 5 12345 LastLast
Results 1 to 10 of 46
  1. #1
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default Using a while statement in an echo.

    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?

    PHP Code:
    $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.
    Last edited by Invent; 30-08-2008 at 02:10 PM.

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Hell no.

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

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

  3. #3
    Join Date
    Jul 2008
    Location
    Leeds, UK
    Posts
    47
    Tokens
    0

    Default

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

    PHP Code:
    $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
    Last edited by Delatory; 28-08-2008 at 08:25 PM.

  4. #4
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Delatory View Post
    Nope that wouldn't work, If you did try that it wouldn't do the script it would just send it to the page.

    PHP Code:
    $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].

  5. #5
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Quote Originally Posted by Dentafrice View Post
    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.

    Quote Originally Posted by Delatory View Post
    Nope that wouldn't work, If you did try that it wouldn't do the script it would just send it to the page.

    PHP Code:
    $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.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    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.

  7. #7
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

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

    and i use echo(" "); too, just a habbit lol ;p
    Coming and going...
    Highers are getting the better of me

  8. #8
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Quote Originally Posted by Dentafrice View Post
    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?

    Quote Originally Posted by MrCraig View Post
    need to close the </select> tag still..

    and i use echo(" "); too, just a habbit lol ;p
    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

  9. #9
    Join Date
    Jul 2005
    Location
    Cymru! :o Bahh
    Posts
    571
    Tokens
    0

    Default

    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.
    Last edited by kreechin; 28-08-2008 at 10:46 PM.

    So A Kiss Is Out Of The Question Then..?

    ♥ My Boy <sinlge> Tbh ♥
    This love isn't good unless it's me and you
    Complicated is the whole point. x

    Theres nothing scarier than getting something you want because then you have something to lose..





  10. #10
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    ""; 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

Page 1 of 5 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •