yunfanny
09-28-2006, 11:13 AM
I have the following code, it seems that the FOR loop is not executed fully, as the output just printing the $letter_query, which is the 2nd line of the FOR loop -- print_r($letter_query);. The rest of the codes in the FOR loop is not executed at all. No error message displayed either. Could anyone help to examine the codes? Thanks a lot !
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Blog Warehouse</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Companies in the Blogosphere (Key word matching)</h1>
<?php
$dbcnx = @mysql_connect('localhost', 'root', 'password');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}
// Select the blog database
if (!@mysql_select_db('ijob')) {
exit('<p>Unable to locate the blog collection database at this time.</p>');
}
$letter_name_query = "select comp_id, comp_name from company_list where comp_ini = '"."a". "'";
$letter_name_result = @mysql_query($letter_name_query);
if(!$letter_name_result)
{
exit ('<p>Error retrieving company names from database!<br />Error: '.mysql_error(). '</p>');
}
$query_array = array();
while ($letter_name_output =mysql_fetch_array($letter_name_result))
{
$letter_name = $letter_name_output['comp_name'];
$letter_name_id = $letter_name_output['comp_id'];
$letter_query = "select id, title, content from blog_entry where title like ";
$letter_query = $letter_query.'"%'.' '.$letter_name.'%"';
$letter_query = $letter_query. " OR content like ". '"%'.' '.$letter_name.'%"';
$query_array[] = $letter_query;
}
$count=count($query_array);
for ($i = 0; $i < $count; $i++)
{
$letter_query = $query_array[$i];
print_r($letter_query);
echo '<p></p>';
$letter_result = @mysql_query($letter_query);
if(!$letter_result)
{ echo '<p> not letter result</p>';
exit ('<p>Error retrieving blog entries from database!<br />'.
'Error: '.mysql_error(). '</p>');
}
while( $letter_output = mysql_fetch_array($letter_result)) {
echo '<p>while loop</p>';
if($letter_output == "")
{echo '<p>empty</p>'; }
if($letter_output != "")
{
echo '<p>result</p>';
$ID = $letter_output['id'];
print_r($ID);
echo '<p></p>';
}
}
}
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Blog Warehouse</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Companies in the Blogosphere (Key word matching)</h1>
<?php
$dbcnx = @mysql_connect('localhost', 'root', 'password');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}
// Select the blog database
if (!@mysql_select_db('ijob')) {
exit('<p>Unable to locate the blog collection database at this time.</p>');
}
$letter_name_query = "select comp_id, comp_name from company_list where comp_ini = '"."a". "'";
$letter_name_result = @mysql_query($letter_name_query);
if(!$letter_name_result)
{
exit ('<p>Error retrieving company names from database!<br />Error: '.mysql_error(). '</p>');
}
$query_array = array();
while ($letter_name_output =mysql_fetch_array($letter_name_result))
{
$letter_name = $letter_name_output['comp_name'];
$letter_name_id = $letter_name_output['comp_id'];
$letter_query = "select id, title, content from blog_entry where title like ";
$letter_query = $letter_query.'"%'.' '.$letter_name.'%"';
$letter_query = $letter_query. " OR content like ". '"%'.' '.$letter_name.'%"';
$query_array[] = $letter_query;
}
$count=count($query_array);
for ($i = 0; $i < $count; $i++)
{
$letter_query = $query_array[$i];
print_r($letter_query);
echo '<p></p>';
$letter_result = @mysql_query($letter_query);
if(!$letter_result)
{ echo '<p> not letter result</p>';
exit ('<p>Error retrieving blog entries from database!<br />'.
'Error: '.mysql_error(). '</p>');
}
while( $letter_output = mysql_fetch_array($letter_result)) {
echo '<p>while loop</p>';
if($letter_output == "")
{echo '<p>empty</p>'; }
if($letter_output != "")
{
echo '<p>result</p>';
$ID = $letter_output['id'];
print_r($ID);
echo '<p></p>';
}
}
}
?>
</body>
</html>