I've a table invitation with coloumns toemail, fromemail, send
I need to print toemail & fromemail from all rows having valid send=1
This is the code that I'm using
<?php
$query = mysql_query("SELECT fromemail,toemail FROM invitations WHERE sent = 1");
if(mysql_num_rows($query)!=0)
{
$row = mysql_fetch_assoc($query);
echo $row['toemail'];
echo $row['fromemail];
}
?>
But this prints only the first row which satisfying the condition.
Help me to get the php code please.
Thanks in advance.
Use this,
$query = mysql_query("SELECT fromemail,toemail FROM invitations WHERE sent = 1");
if(mysql_num_rows($query)!=0)
{
while($row = mysql_fetch_assoc($query)) {
echo $row['toemail'];
echo $row['fromemail];
}
}
You can either use following -
$query = mysql_query("SELECT fromemail,toemail FROM invitations WHERE sent = 1");
if(mysql_num_rows($query)!=0)
{
$result = mysql_result($query);
foreach($result in $row) {
echo $row->toemail;
echo $row->fromemail;
}
}
P.S. - MYSQL extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.
Reference - http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated