Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mySQL & PHP - multiple query/loop question

Status
Not open for further replies.

pain4u

Technical User
Jun 26, 2001
64
US
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 = &quot;linedelimited.txt&quot;;
$fp = fopen($file,&quot;r&quot;) or die(&quot;Couldn't open $file&quot;);
while(!feof($fp))
{$line = fgets($fp,1024);
if(stristr($line,&quot;@&quot;))
$lines[] = $line;
else
continue;
}
fclose($fp);
return true;
}

if(fileBreakupLines())
{$dba = array(&quot;host&quot;,&quot;user&quot;,&quot;password&quot;,&quot;database&quot;);
$link = mysql_connect($dba[0],$dba[1],$dba[2]);
if(!$link)
die(&quot;Couldn't connect to mysqld!&quot;);

mysql_select_db($dba[3],$link) or die(&quot;Couldn't open $dba[3]: &quot;.mysql_error());

$rows = array();

for($x=0;$x<count($lines);$x++)
{$query = &quot;SELECT * FROM email_list WHERE email='$lines[$x]'&quot;;
$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.&quot;<br>&quot;;}
print count($row).&quot; = total number of fields for row!<br><br>&quot;;
}

?> [b]- PAINKILLER [/b]
 
no connection support multiple statements opened at the same time. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top