A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Hey easy comma question

  1. #1
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337

    Hey easy comma question

    Hey guys, i have a question, what is the php-sql code for taking one column in a database and seperating each value with a comma, then outputing that data so only you can see it (basically how can you run this file online in a way only you can run it?) ?

    Thanks
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  2. #2
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    help anyone?
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Explain a bit more. Are you actually trying to grab a whole column? Or a row?

    And what do you mean, outputting the data so only you can see it? Password protected?

  4. #4
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    A whole column whose name is "email"

    And actually forget about the outputting data thing, yeah i meant password protecting it, i know how to do it, that was a stupid question.

    So i need to be able to take every value from one column, and add a comma to each one of those values. How can i do that?
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  5. #5
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    You could do something simply like: SELECT email FROM my_table;

    And that will select all of the email addresses from my_table. You can then loop over your rows and just build out one large string separated by commas. Something like this:
    PHP Code:
    $my mysql_connect(....);
    mysql_select_db('awesome_db'$my);
    $query 'SELECT email FROM my_table';
    $result mysql_query($query$my);

    $emails = array();
    while(
    $row mysql_fetch_array($result)) array_push($emails$row[0]);

    die(
    implode(','$emails)); 
    As for password protection, there's a million ways you can do it. Explain your goal with it so I can point you in the right direction.

  6. #6
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    Alrite i did that and heres my script

    PHP Code:
    <? php


    mysql_connect('localhost','********','*****');

    mysql_select_db('********');

    $query = "SELECT email FROM ****** ORDER BY id desc";


    $result = mysql_query($query);

    $emails = array();

    while($row = mysql_fetch_array($result)) array_push($emails, $row[0]);

    die(implode(',', $emails)); 

    print "$emails";




    ?>
    i keep getting this abnoxious error

    Parse error: syntax error, unexpected T_STRING in /home/bostonh1/public_html/invitez/getLokerzList.php on line 4

    what the hell?!
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  7. #7
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Is there more to your script? Which is line 4?

    And do you realize that you're using print after my call to die? die is the same thing as exit. It's the last output from your script.

    And last, your space between <? php will cause a problem if that's not a typo. There is no space: <?php

  8. #8
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    yea it worked haha turned out to be the space between the "<? php"

    haha thanks
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  9. #9
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    Hey, sorry i have another problem

    so i want to select only a specific amount of rows from one variable to another (according to the id column)

    so i changed the above script's query part to this

    PHP Code:
    $query "SELECT * FROM ******* WHERE id BETWEEN 240 AND 245 ORDER BY id desc";

    $result mysql_query($query);

    $row mysql_fetch_array($result);

    echo 
    "$row['email']"
    but now, i get this error
    PHP Code:
    Parse errorsyntax errorunexpected T_ENCAPSED_AND_WHITESPACEexpecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/bostonh1/public_html/invitez/getLokerzList.php on line 31 
    can you help me out?

    thanks


    but now,
    Last edited by flashtrickster; 11-11-2009 at 11:17 PM.
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  10. #10
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Again, you should probably point out what line 31 is.

    And why do you keep echoing out a variable and enclosing it in quotes? You do realize that that is pointless, right?

    You can just as easily do: echo $row['email'];

  11. #11
    Senior Member
    Join Date
    Sep 2007
    Location
    USA................. Posts: 87,683
    Posts
    337
    yeah, haha once again your echo tip was usefull, i never knew that and ive been using php for like 2 years. i figured out a workaround and it was this
    PHP Code:
    while($row mysql_fetch_array($result)){
        echo 
    $row['email'].",";


    thanks!
    ...♠♣♦♥::Trickmaster::♥♦♣♠...
    ╔════════════════════╗
    ║------------------------- ║
    ║-- www.Trixmasta.com--- ║
    ║------------------------- ║
    ╚════════════════════╝

  12. #12
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Oh, yeah, I missed that. You are selecting multiple rows, so you need a loop to iterate over them all.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center