Does PHP not allow you to loop through multiple queries??
I am trying to use a loop to issue multiple select queries. It looks like as if the 2nd result loop overwrites the 1st result loop. Does anyone know why it is doing that?
I've even gone as far as to create an array (in an attempt to save the results) for the row results. But not even that is working...what am I doing wrong??
HOW CAN I ISSUE MULTIPLE QUERIES?...I'm confused...I've been at this for hours, and I would appreciate any help!
HERE IS THE CODE:
<?php
$lines = array();
function fileBreakupLines()
{global $lines;
$file = "linedelimited.txt";
$fp = fopen($file,"r" or die("Couldn't open $file"
while(!feof($fp))
{$line = fgets($fp,1024);
if(stristr($line,"@")
$lines[] = $line;
else
continue;
}
fclose($fp);
return true;
}
if(fileBreakupLines())
{$dba = array("host","user","password","database"
$link = mysql_connect($dba[0],$dba[1],$dba[2]);
if(!$link)
die("Couldn't connect to mysqld!"
mysql_select_db($dba[3],$link) or die("Couldn't open $dba[3]: ".mysql_error());
$rows = array();
for($x=0;$x<count($lines);$x++)
{$query = "SELECT * FROM email_list WHERE email='$lines[$x]'";
$result = mysql_query($query,$link);
while($row = mysql_fetch_assoc($result))
{$rows[] = $row;
$rows[] = $row[email_id];
$rows[] = $row[user_id];
}
mysql_free_result($result);
}
foreach($rows as $row)
{print $row."<br>";}
print count($row)." = total number of fields for row!<br><br>";
}
?> [b]- PAINKILLER [/b]
I am trying to use a loop to issue multiple select queries. It looks like as if the 2nd result loop overwrites the 1st result loop. Does anyone know why it is doing that?
I've even gone as far as to create an array (in an attempt to save the results) for the row results. But not even that is working...what am I doing wrong??
HOW CAN I ISSUE MULTIPLE QUERIES?...I'm confused...I've been at this for hours, and I would appreciate any help!
HERE IS THE CODE:
<?php
$lines = array();
function fileBreakupLines()
{global $lines;
$file = "linedelimited.txt";
$fp = fopen($file,"r" or die("Couldn't open $file"
while(!feof($fp))
{$line = fgets($fp,1024);
if(stristr($line,"@")
$lines[] = $line;
else
continue;
}
fclose($fp);
return true;
}
if(fileBreakupLines())
{$dba = array("host","user","password","database"
$link = mysql_connect($dba[0],$dba[1],$dba[2]);
if(!$link)
die("Couldn't connect to mysqld!"
mysql_select_db($dba[3],$link) or die("Couldn't open $dba[3]: ".mysql_error());
$rows = array();
for($x=0;$x<count($lines);$x++)
{$query = "SELECT * FROM email_list WHERE email='$lines[$x]'";
$result = mysql_query($query,$link);
while($row = mysql_fetch_assoc($result))
{$rows[] = $row;
$rows[] = $row[email_id];
$rows[] = $row[user_id];
}
mysql_free_result($result);
}
foreach($rows as $row)
{print $row."<br>";}
print count($row)." = total number of fields for row!<br><br>";
}
?> [b]- PAINKILLER [/b]