Current location: Hot Scripts Forums » Programming Languages » PHP » Search Results (New Line)


Search Results (New Line)

Reply
  #1 (permalink)  
Old 09-29-04, 06:28 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Search Results (New Line)

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 ;)

   
$query "SELECT * FROM $db_table"
   
$result mysql_query($query); 
   
$numrows mysql_num_rows($result); 
   while(
$row mysql_fetch_array($result)){ 

   if(
preg_match("/$words/i"$row[$mysql_row]))
   { 

/*
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]);
    
          
//echo($newnews); 
          //echo($rawphone);
          //echo($rawmobile);
          //echo($rawfax);
          //echo($rawemail);
          //echo($rawweb);
      
$foundcount++; 
   } 
   
$totalcount++; 
   } 
if(
is_null($foundcount)){$foundcount=0;} 
$rawfound = ("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>Found $foundcount entries out of $totalcount</b></font>"); 

?>
<? 
echo ($newnews);?>
<? 
echo ($rawphone);?>
<? 
echo ($rawmobile);?>
<? 
echo ($rawfax);?>
<? 
echo ($rawemail);?>
<? 
echo ($rawweb);?>
what is wrong with the code?
Reply With Quote
  #2 (permalink)  
Old 10-01-04, 07:01 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Pagination

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']))
 
  {
   
$Result_Set=0;
   
$SQL.=" LIMIT $Result_Set$Per_Page";
   }else
   {
 
  
$Result_Set=$_GET['Result_Set'];
   
$SQL.=" LIMIT $Result_Set$Per_Page";
 
  }
// 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);
 
   
$Product=$SQL_Array['first'];
    
$Description=$SQL_Array['last'];
  
  echo 
"$Product - $Description<BR><BR>";
    }
// Create Next / Prev Links and $Result_Set Value
if ($Total>0)
   {
   if (
$Result_Set<$Total && 
$Result_Set>0)
      {
      
$Res1=$Result_Set-$Per_Page;
echo 
'<A HREF="results.php?Result_Set=$Res1&Keyword='$_REQUEST['Keyword'].'"><;<; Previous Page</A> '
      }
   
// Calculate and Display Page 
# Links
   
$Pages=$Total $Per_Page;
   if (
$Pages>1)
      {
      for (
$b=0,$c=1
$b $Pages$b++,$c++)
          {
          
$Res1=$Per_Page $b;
       
   echo 
'<A HREF="results.php?Result_Set=$Res1&Keyword='.$_REQUEST['Keyword'].'"> 

        '
$c .'</A> n'
          }
      }
   if (
$Result_Set>=&& $Result_Set<$Total)
 
     {
      
$Res1=$Result_Set+$Per_Page;
      if (
$Res1<$Total)
         
{
   echo 
' <A HREF="results.php?Result_Set=$Res1&Keyword='.$_REQUEST['Keyword'].'"> 

       Next Page >></A>'
;
         }
      }
   }
// Close Database Connection
mysql_close($Connection);
?>
i first thought it was here,

PHP Code:

$SQL="SELECT COUNT(*) AS Total FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%'";

$SQL_Result=mysql_db_query($DB_Name$SQL); 

i changed it too this

$srch=".REQUEST['Keyword']"
$sql=("SELECT * FROM contacts WHERE first LIKE '%$srch%'");

didnt seem to work.
Reply With Quote
  #3 (permalink)  
Old 10-02-04, 09:57 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Give this a try:

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);

if (
$_GET['Result_Set'])
{
    
$Result_Set=$_GET['Result_Set'];
}
else
{
    
$Result_Set 0;
}

$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);

while (
$SQL_Result_Array mysql_fetch_array($SQL_Result))
{
    
$Product $SQL_Result_Array['first'];
    
$Description $SQL_Result_Array['last'];
    echo 
"$Product - $Description<BR><BR>";
}

// ----------------------------------------
// NOTHING MODIFIED BELOW
// ----------------------------------------

// Create Next / Prev Links and $Result_Set Value
if ($Total>0)
   {
   if (
$Result_Set<$Total &&
$Result_Set>0)
      {
      
$Res1=$Result_Set-$Per_Page;
echo 
'<A HREF="results.php?Result_Set=$Res1&Keyword='$_REQUEST['Keyword'].'"><;<; Previous Page</A> ';
      }
   
// Calculate and Display Page
# Links
   
$Pages=$Total $Per_Page;
   if (
$Pages>1)
      {
      for (
$b=0,$c=1;
$b $Pages$b++,$c++)
          {
          
$Res1=$Per_Page $b;
       
   echo
'<A HREF="results.php?Result_Set=$Res1&Keyword='.$_REQUEST['Keyword'].'">

        '
$c .'</A> n';
          }
      }
   if (
$Result_Set>=&& $Result_Set<$Total)

     {
      
$Res1=$Result_Set+$Per_Page;
      if (
$Res1<$Total)
         
{
   echo 
' <A HREF="results.php?Result_Set=$Res1&Keyword='.$_REQUEST['Keyword'].'">

       Next Page >></A>'
;
         }
      }
   }
// Close Database Connection
mysql_close($Connection);
?>
BTW, use mysql_query instead of mysql_db_query. mysql_db_query is deprecated in current versions of PHP.
Reply With Quote
  #4 (permalink)  
Old 10-02-04, 09:02 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
now i get these errors.

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
Reply With Quote
  #5 (permalink)  
Old 10-02-04, 09:57 PM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
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 
Also, for
PHP Code:

$SQL_Result mysql_query($SQL$DB_Name); 

Replace it with:
PHP Code:

$SQL_Result mysql_query($SQL$Connection); 


//Or just:

$SQL_Result mysql_query($SQL); 
See how that goes...
__________________
suf.id.au
Reply With Quote
  #6 (permalink)  
Old 10-02-04, 11:09 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Pagination

it still has

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
Reply With Quote
  #7 (permalink)  
Old 10-02-04, 11:20 PM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Forgot to remove 'AS Total' from $SQL

PHP Code:

//replace


$SQL "SELECT * AS Total FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%'  LIMIT $Result_Set$Per_Page";

//with

$SQL "SELECT * FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set$Per_Page";

//for both $SQL 
Give that a try.
__________________
suf.id.au
Reply With Quote
  #8 (permalink)  
Old 10-02-04, 11:30 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Pagination

got this

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

i tried to change it too

$Total = mysql_num_rows($SQL, $Connection);

and

$Total = mysql_num_rows($Connection);

didnt work

as you can tell i dont know what im doing

im at php.net trying to at least read up on it.
Reply With Quote
  #9 (permalink)  
Old 10-02-04, 11:39 PM
MrDarko's Avatar
MrDarko MrDarko is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Pagination

i dont have to have the
ORDER BY ProductID"; added to

PHP Code:

$SQL "SELECT * FROM contacts WHERE first LIKE '%".$_REQUEST['Keyword']."%' LIMIT $Result_Set$Per_Page"
thats what originally was there at the end. i didnt think it was important.
Reply With Quote
  #10 (permalink)  
Old 10-03-04, 12:10 AM
sufyan sufyan is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Melbourne, AU
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Did you change both $SQL or just one?

If you changed both, it should work. It's wierd if it doesn't. You don't get the error on line 28 anymore, right?

So, this is how it should be:

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);
mysql_select_db($DB_Name$Connection);

if (
$_GET['Result_Set'])
{
    
$Result_Set=$_GET['Result_Set'];
}
else
{
    
$Result_Set 0;
}

$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);

while (
$SQL_Result_Array mysql_fetch_array($SQL_Result))
{
    
$Product $SQL_Result_Array['first'];
    
$Description $SQL_Result_Array['last'];
    echo 
"$Product - $Description<BR><BR>";
}

// ----------------------------------------
// NOTHING MODIFIED BELOW
// ----------------------------------------
__________________
suf.id.au
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirection back to a page from form submit DAL Perl 11 03-21-05 02:45 PM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 04:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.