|
-
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--- ║
║------------------------- ║
╚════════════════════╝
-
...♠♣♦♥::Trickmaster::♥♦♣♠...
╔════════════════════╗
║------------------------- ║
║-- www.Trixmasta.com--- ║
║------------------------- ║
╚════════════════════╝
-
Bearded (M|G)od
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?
-
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--- ║
║------------------------- ║
╚════════════════════╝
-
Bearded (M|G)od
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.
-
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--- ║
║------------------------- ║
╚════════════════════╝
-
Bearded (M|G)od
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
-
yea it worked haha turned out to be the space between the "<? php"
haha thanks
...♠♣♦♥::Trickmaster::♥♦♣♠...
╔════════════════════╗
║------------------------- ║
║-- www.Trixmasta.com--- ║
║------------------------- ║
╚════════════════════╝
-
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 error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting 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--- ║
║------------------------- ║
╚════════════════════╝
-
Bearded (M|G)od
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'];
-
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--- ║
║------------------------- ║
╚════════════════════╝
-
Bearded (M|G)od
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|