Looping through the Database

the mail() function

Moderators: macek, egami, gesf

lexxsc2
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jan 16, 2012 12:00 pm

Looping through the Database

Postby lexxsc2 » Sun Mar 18, 2012 5:43 am

Hi,guys
So I'm trying to make a script that loops through my Database and checks if a value that I've defined is equal to one from the database and then does something.
Example:
if I define
$myDate = date("d/m/Y");
and I have a column in my database that is called date.I want to check if $myDate = date and then do something(like sending an e-mail). After that the script should check the next row and so to the end of the mySQL database.
Thanks in advance for the answers.

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Looping through the Database

Postby freshnet » Thu Mar 22, 2012 2:48 pm

You'll want to fetch your query results into a variable and then use a foreach on that variable, e.g.

Code: Select all

$sql = mysqli_query($mysqli,"SELECT x FROM y");
$sql_result = mysqli_fetch_array($sql);

foreach ($sql_result as $value)
{
if ($value == $something_else)
{some code}
else
{some more code}
}


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron