last day (14 days later) » 

12:21 PM
1
A: How to select all emails from mysql table and assign it to $to of mail function in php?

Kool-Minduse group_concat for it $query = 'select group_concat(email separator ',') as email FROM users'; if ($result=mysqli_query($con,$query)) { // Fetch one and one row while ($row=mysqli_fetch_row($result)) { $to = $row; } // Free result set mysqli_free_result($result); } $t...

 
If i use select group_concat(email separator ',') FROM users With my code then "Notice: Undefined index: email in......" is display may be in $allemail =$row["email"]; email is act as a index etc
How i use your suggested code with my code ?
 
see now updated answer forget to ad alias
use select group_concat(email separator ',') as email FROM users
 
Ok, i test $allemail =$row["email"]; with echo it holds all emails with comma now i push code to server i hope so it may works.
 
Yhea buddy it will work.
 
Got Error : Please Try Again ! the else condition is running. Something i am missing i think !
 
12:21 PM
echo $result->num_rows; exit; and see what's the count
 
When i echo it shows like 1,a@aa.com,A@g.com,An@a.com,dsa@ds,Harry@mail.com etc. can this 1 creates any issue ?
 
hi
 
hi can you see my above post
 
actually database query is after your mail function i.e. $allemails should be after datavase connection
it's issue of ordering
please share your whole code?
 
ok
 
12:24 PM
i'll correct the order
 
You can see it on my post all code is their !
 
ok
 
Thanks !
 
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";


$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "select group_concat(email separator ',') as email FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0)
{

while($row = $result->fetch_assoc())
{
$allemail =$row["email"];
}
}
else {
echo "0 results";exit;
}
$conn->close();
place this code after
see this
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";


$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "select group_concat(email separator ',') as email FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0)
hope you understood
 
I am little bit confused !
 
12:38 PM
ok
i mean u should query first and then save the result in variable and then use it in $to
u r doing reverse
so put mail funxtionality after mysql query
 
ok
 
all of your codes should b in isset if condition
done kya?
got it buddy
i'm leaving for the day
 
1:13 PM
fine thanks really its work
Can you please suggest any tutorials for php and for mysql actually i am a front end developer and beginner in php so, facing everyday a new problems in php. Any, suggestions ?
 

last day (14 days later) »