maxd gaming
08-17-2004, 11:06 PM
I have tried EVERYTHING, googled for EVERYTHING and done EVERYTHING. Here is my code:
<?
$link = mysql_connect("localhost","ownedfg_user","password123")
or die("ERROR: Could not connect to database!");
mysql_select_db("search");
print "<html><head><title>My Search Engine</title></head><body>\n";
if( $_POST['keyword'] )
{
/* Connect to the database: */
/* Get timestamp before executing the query: */
$start_time = getmicrotime();
/* Set $keyword and $results, and use addslashes() to
* minimize the risk of executing unwanted SQL commands: */
$keyword = addslashes( $_POST['keyword'] );
$results = 100;
$exploded = explode(" ", $keyword);
$nv = count($exploded);
for($b=0; $b < $nv; $b++)
{
$wor =$exploded[$b];
/* Execute the query that performs the actual search in the DB: */
$aresult = mysql_query(" SELECT p.page_url AS url, COUNT(*) AS occurrences, COUNT(*) AS inlinks, p.title AS title
FROM page p, word w, occurrence o, links l
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word = '$wor' AND
l.inpage_id = p.page_id
GROUP BY p.page_id
ORDER BY inlinks DESC
LIMIT $results" );
/* Get timestamp when the query is finished: */
$end_time = getmicrotime();
/* Present the search-results: */
print "<h2>Search results for '".$wor."':</h2>\n";
$i = 0;
$row = mysql_fetch_array($aresult); //error
while($row != false)
{
$i++;
if($row['title'] == "")
{
print "$i. <a href='".$row['url']."'>".$row['url']."</a>\n";
}
else
{
print "$i. <a href='".$row['url']."'>".$row['title']."</a>\n";
}
print "(inbounds: ".$row['occurrences'].")<br><br>\n";
}
$row = mysql_fetch_array($aresult); //error
}
/* Present how long it took the execute the query: */
print "query executed in ".(substr($end_time-$start_time,0,5))." seconds.";
}
else
{
/* If no keyword is defined, present the search page instead: */
print "<form method='post'> Keyword:
<input type='text' size='20' name='keyword'>\n";
print "Results: <select name='results'><option value='5'>5</option>\n"; //Not used
print "<option value='10'>10</option><option value='15'>15</option>\n";
print "<option value='20'>20</option></select>\n";
print "<input type='submit' value='Search'></form>\n";
}
print "</body></html>\n";
mysql_close($link);
/* Simple function for retrieving the current timestamp in microseconds: */
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ownedfg/public_html/inter/search/index.php on line 45
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ownedfg/public_html/inter/search/index.php on line 59
Those are the errors, the lines are marked. The tables are
CREATE TABLE page (
page_id int(10) unsigned NOT NULL auto_increment,
page_url varchar(200) NOT NULL default '',
title varchar(255) NOT NULL default '',
PRIMARY KEY (page_id)
) TYPE=MyISAM;
CREATE TABLE word (
word_id int(10) unsigned NOT NULL auto_increment,
word_word varchar(50) NOT NULL default '',
PRIMARY KEY (word_id)
) TYPE=MyISAM;
CREATE TABLE occurrence (
occurrence_id int(10) unsigned NOT NULL auto_increment,
word_id int(10) unsigned NOT NULL default '0',
page_id int(10) unsigned NOT NULL default '0',
PRIMARY KEY (occurrence_id)
) TYPE=MyISAM;
CREATE TABLE links (
link_id int(10) unsigned NOT NULL auto_increment,
inpage_id int(10) unsigned NOT NULL default '0',
outpage_id int(10) unsigned NOT NULL default '0',
PRIMARY KEY (link_id)
) TYPE=MyISAM;
I have spent 5 hours trying to fix it..... please... help... ask me any questions I will try to answer them.
<?
$link = mysql_connect("localhost","ownedfg_user","password123")
or die("ERROR: Could not connect to database!");
mysql_select_db("search");
print "<html><head><title>My Search Engine</title></head><body>\n";
if( $_POST['keyword'] )
{
/* Connect to the database: */
/* Get timestamp before executing the query: */
$start_time = getmicrotime();
/* Set $keyword and $results, and use addslashes() to
* minimize the risk of executing unwanted SQL commands: */
$keyword = addslashes( $_POST['keyword'] );
$results = 100;
$exploded = explode(" ", $keyword);
$nv = count($exploded);
for($b=0; $b < $nv; $b++)
{
$wor =$exploded[$b];
/* Execute the query that performs the actual search in the DB: */
$aresult = mysql_query(" SELECT p.page_url AS url, COUNT(*) AS occurrences, COUNT(*) AS inlinks, p.title AS title
FROM page p, word w, occurrence o, links l
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word = '$wor' AND
l.inpage_id = p.page_id
GROUP BY p.page_id
ORDER BY inlinks DESC
LIMIT $results" );
/* Get timestamp when the query is finished: */
$end_time = getmicrotime();
/* Present the search-results: */
print "<h2>Search results for '".$wor."':</h2>\n";
$i = 0;
$row = mysql_fetch_array($aresult); //error
while($row != false)
{
$i++;
if($row['title'] == "")
{
print "$i. <a href='".$row['url']."'>".$row['url']."</a>\n";
}
else
{
print "$i. <a href='".$row['url']."'>".$row['title']."</a>\n";
}
print "(inbounds: ".$row['occurrences'].")<br><br>\n";
}
$row = mysql_fetch_array($aresult); //error
}
/* Present how long it took the execute the query: */
print "query executed in ".(substr($end_time-$start_time,0,5))." seconds.";
}
else
{
/* If no keyword is defined, present the search page instead: */
print "<form method='post'> Keyword:
<input type='text' size='20' name='keyword'>\n";
print "Results: <select name='results'><option value='5'>5</option>\n"; //Not used
print "<option value='10'>10</option><option value='15'>15</option>\n";
print "<option value='20'>20</option></select>\n";
print "<input type='submit' value='Search'></form>\n";
}
print "</body></html>\n";
mysql_close($link);
/* Simple function for retrieving the current timestamp in microseconds: */
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ownedfg/public_html/inter/search/index.php on line 45
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ownedfg/public_html/inter/search/index.php on line 59
Those are the errors, the lines are marked. The tables are
CREATE TABLE page (
page_id int(10) unsigned NOT NULL auto_increment,
page_url varchar(200) NOT NULL default '',
title varchar(255) NOT NULL default '',
PRIMARY KEY (page_id)
) TYPE=MyISAM;
CREATE TABLE word (
word_id int(10) unsigned NOT NULL auto_increment,
word_word varchar(50) NOT NULL default '',
PRIMARY KEY (word_id)
) TYPE=MyISAM;
CREATE TABLE occurrence (
occurrence_id int(10) unsigned NOT NULL auto_increment,
word_id int(10) unsigned NOT NULL default '0',
page_id int(10) unsigned NOT NULL default '0',
PRIMARY KEY (occurrence_id)
) TYPE=MyISAM;
CREATE TABLE links (
link_id int(10) unsigned NOT NULL auto_increment,
inpage_id int(10) unsigned NOT NULL default '0',
outpage_id int(10) unsigned NOT NULL default '0',
PRIMARY KEY (link_id)
) TYPE=MyISAM;
I have spent 5 hours trying to fix it..... please... help... ask me any questions I will try to answer them.
