Looping through the Database

the mail() function

Moderators: macek, egami, gesf

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

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.
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
php-forum Active User
php-forum Active User
Posts: 335
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}
{some more code}

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 2 guests