I have this code i use to search my database, for some reason i cannot get the lines to appear right, im also trying to make them on a new line.
PHP Code:
<head>
<link rel="stylesheet" type="text/css" href="includes\css.css">
</head>
<html>
<body>
<font face="tahoma" size="4"> <font face="Verdana, Arial, Helvetica, sans-serif">Mysql
Search</font></font>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
<font face="Verdana, Arial, Helvetica, sans-serif"> Specific Word or Phrase
<input type="text" name="words" value="<?php echo($words); ?>">
<br>
<br>
<input type="hidden" name="good" value="yes">
<input type="submit" value="Search">
</font>
</form>
<p><font face="Verdana, Arial, Helvetica, sans-serif"><br>
<br>
<?
/*
This script is set up specifically for me so some things will need changing.
I made this script because there is a lack of good mysql serching scripts out there.
*/
if($_POST['good']=='yes')
{
echo("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>Results for $words</b></font><br><br>");
$location = "mysql11.secureserver.net"; // database host (localhost)
$username = "tests"; // mysql username
$password = "bobsters"; //mysql password
$database = "tests"; //mysql database name
$db_table = "contacts"; // mysql table name to search
$mysql_row = "first"; // This is the row in your mysql database that you want to search for text in.
$last = "last";
$phone = "phone";
$mobile = "mobile";
$fax = "fax";
$email = "email";
$web = "web";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "ALTER TABLE $db_table ORDER BY id DESC";
$result = mysql_query($query); // bad coding yes ;)
/*
event_id
event_date
event_venue
event_headline
event_town
are all rows in my mysql table. You must replace them with your own rows / rows
*/
$rawid = ($row[$id]);
$rawlast = ($row[$last]); //yes strange variable names. It works so it doesnt matter.
$rawphone = ($row[$phone]); //T just grab extra data to be added with the search tool
$rawmobile = ($row[$mobile]);
$rawfax = ($row[$fax]);
$rawemail = ($row[$mail]);
$rawweb = ($row[$web]);
$newnews = preg_replace("/$words/i", "<b><font color=\"red\">$words$rawlast</font></b>", $row[$mysql_row]);
sensing that last question was too broad, i decided to use a different code. everything has been working good except one part of it. i found a few errors myself but i cannot see it. It shows the results fine, but the pages function does not.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 35
PHP Code:
<?
// Set Script Variables
$DB_Host="mysql12.secureserver.net";
$DB_Name="test";
$DB_User="test";
$DB_Pass="cheese";
$Per_Page=10;
// Open MySQL Connection
$Connection=mysql_connect($DB_Host, $DB_User, $DB_Pass);
// Run The Query Without a Limit to get Total result
$SQL="SELECT COUNT(*) AS Total FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%'";
$SQL_Result=mysql_db_query($DB_Name, $SQL);
$SQL_Result_Array=mysql_fetch_array($SQL_Result);
$Total=$SQL_Result_Array['Total'];
// Create a new SELECT Query with the ORDER BY
// clause and without the COUNT(*)
$SQL="SELECT
* FROM contacts WHERE first
LIKE '%".$_REQUEST['Keyword']."%'";
// Append a LIMIT clause to the SQL statement
if (empty($_GET['Result_Set']))
}
// Run The Query With a Limit to get result
$SQL_Result=mysql_db_query($DB_Name, $SQL);
$SQL_Rows=mysql_num_rows($SQL_Result);
// Display Results using a for loop
for
($a=0; $a < $SQL_Rows; $a++)
{
$SQL_Array=mysql_fetch_array($SQL_Result);
$SQL = "SELECT * AS Total FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set, $Per_Page";
$Total = mysql_num_rows($SQL);
// Run The Query Without a Limit to get Total result
$SQL = "SELECT * AS Total FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set, $Per_Page";
$SQL_Result = mysql_query($SQL, $DB_Name);
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 22
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 26
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 28
Sorry about that. Just looked over it again. Try adding:
PHP Code:
$Connection = mysql_connect($DB_Host, $DB_User, $DB_Pass); //this is already in your code (line 10)
mysql_select_db($DB_Name, $Connection); // add this line, this selects the database
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 22
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/s/t/r/strykstaguy/html/tests/results.php on line 28
$SQL = "SELECT * FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set, $Per_Page";
$Total = mysql_num_rows($SQL);
// Run The Query Without a Limit to get Total result
$SQL = "SELECT * FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set, $Per_Page";
$SQL_Result = mysql_query($SQL);