• 0

search script


Question

9 answers to this question

Recommended Posts

  • 0
  soil said:
:unsure: like when u search the forum it shows all the topics with that title name.

585472280[/snapback]

you'll probably want to use php. i made something like that for my website (link below). it's really simple and all you need is:

searching for 'neowin' in 'Post titles' in database called 'Forum'

SELECT col1, col2 etc. FROM 'Forum WHERE ('Post titles' LIKE 'neowin');

you can also add in ORDER functions to sort by date or whatever you like.

Link to comment
https://www.neowin.net/forum/topic/285296-search-script/#findComment-585472299
Share on other sites

  • 0

i'm at work right now so i can't access my code back home, but all you need is just a simple select statement to search the database for the info you need.

so in php it goes something like this:

$sql = "SELECT * FROM .... etc. etc." // insert your sql query here

mysql_query($sql);

don't forget to connect to the localhost first!

Link to comment
https://www.neowin.net/forum/topic/285296-search-script/#findComment-585472442
Share on other sites

  • 0

how does it get the info from the form tho?

i found this 1 on the net but couldnt get it to work...

<form method=post action="search.php">arch For:
<p>
User Name: <input type=text name=user size=25 maxlength=25>
<p>
Password: <input type=text name=passwd size=25 maxlength=25>
<p>
<input type=submit>
</form>                                             

//search.php
<?
//You should now this but be sure to connect to your database or this is useless. :/
if ($user == "")
{$user = '%';}

if ($passwd == "")
{$passwd = '%';}
// $user and $passwd are the two column names I used.  Change this to fit your database
$result = mysql_query ("SELECT * FROM yourtable
                         WHERE user LIKE '%$user%'
                         AND passwd LIKE '%$passwd%'
                       ");

if ($row = mysql_fetch_array($result)) {

do {
  PRINT "<b>User Name:?????</b>     ";
  print $row["user"];
  print (" ");
  print ("<br>");
  PRINT "<b>Passwd:?????</b>     ";
  print $row["passwd"];
  print ("<p>");
  PRINT "<b>FirstName:?????</b>     ";
  print $row["firstname"];
  print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}

//The end result prints the username / passwd / firstname / lastname / ID / email
//you will have to change these fields also to fit your needs
?>

Edited by soil
Link to comment
https://www.neowin.net/forum/topic/285296-search-script/#findComment-585472495
Share on other sites

  • 0

:unsure: ok ermm i editd it but its not showing what i search forr :no:

  Quote
        <form method="post" name="search" action="index.php?page=search">

 

    <table width="190%" border="0" cellspacing="0" cellpadding="0">

            <tr>

              <td height="20">

<div align="center">

                  <input type=text name=search size=28 maxlength=25 class=dropdown>

                </div></td>

            </tr>

            <tr>

              <td height="20">

<div align="center">

                  <input name="submit" type=submit class=button value="Search">

                </div></td>

            </tr>

          </table>

  </form>

  Quote
<TABLE cellSpacing="1" cellPadding="4" width="100%" border="0">

  <TBODY>

    <TR>

      <TD class=header align=middle width=69 height=10><FONT

                  size=1><a class=link href="index.php?page=files">Added</a></FONT></TD

      <TD width="381" height=10 align=middle class=header><FONT

                  size=1><a class=link href="index.php?page=sort-name">Name</a></FONT></TD

      <TD class=header align=middle width=117 height=10><FONT

                  size=1><a class=link href="index.php?page=sort-author">Author</a></FONT></TD

      <TD class=header align=middle width=76 height=10><FONT

                  size=1><a class=link href="index.php?page=sort-section">Section</a></FONT></TD

      <TD class=header align=middle width=83 height=10><FONT

                  size=1><a class=link href="index.php?page=sort-version">Version</a></FONT></TD

    </TR>

<?php

include("db_config.php");

if ($search == "")

{$search = '%';}

$result = mysql_query ("SELECT * FROM files

                        WHERE search LIKE '%$downloadsignername%'

      WHERE search LIKE '%$info%'

                      ");

if ($row = mysql_fetch_array($result)) {

do {

?>

  <TR>

    <TD width="69" align=middle class=primary ><font size="1"><?php echo date("m-d-Y", $row['date']); ?></font></TD>

    <TD width="381" class=secondary><a class=link href="<?php echo $row['downloadurl']; ?>" target="_blank"><?php echo $row['info']; ?></a></TD>

    <TD width="117" class=primary><div align="center"><a class=link href="mailto:<?php echo $row['downloademail']; ?>"><?php echo $row['downloadsignername']; ?></a></div></TD>

    <TD width="76" align=middle class=secondary><div align="center"><font size="1"><?php echo $row['downloadpic']; ?></font></div></TD>

    <TD width="83" align=middle class=primary><div align="center"><font size="1"><?php echo $row['version']; ?></font></div></TD>

  </TR>

<?php

} while($row = mysql_fetch_array($result));

} else {print "Sorry, no records were found!";}

?>

</table>

Edited by soil
Link to comment
https://www.neowin.net/forum/topic/285296-search-script/#findComment-585472869
Share on other sites

  • 0
  Quote
include("db_config.php");
if ($search == "")
{$search = '%';}
$result = mysql_query ("SELECT * FROM files
                        WHERE search LIKE '%$downloadsignername%'
       WHERE search LIKE '%$info%'
               ");

I'm not sure how PHP is set up on your server, but you might need to use $_POST. Also, a field name should follow 'WHERE' and the search keyword should follow 'LIKE'.

For example

include("db_config.php");
$search = $_POST['search'];
if ($search == "")
    {$search = '%';}
$result = mysql_query ("SELECT * FROM files
                         WHERE downloadsingername LIKE '%$search%'
                         OR info LIKE '%$search%'");

(I'm assuming 'downloadsingername' [you made a typo there, BTW] and 'info' are fields in your table.)

Link to comment
https://www.neowin.net/forum/topic/285296-search-script/#findComment-585473506
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Only option I want is to disable the system tray overflow menu and always show icons, W11 added option to hide the menu but then icons will still go there instead of the tray.
    • Windows 11 blocks Google Chrome due to a Microsoft safety feature, fix out by Sayan Sen Microsoft has a parental control and safety feature called "Microsoft Family Safety" which allows users to create safe spaces for their family members for browsing the web by setting up filters so as to block and filter inappropriate content and limit browsing to kid-friendly and family friendly content. However, as it turns out, following Chrome version updates 137.0.7151.68, 137.0.7151.69, Google's web browser is getting automatically blocked by Microsoft Family Safety as affected users have reported that the browser will automatically close or crash and then fail to reopen. Thus if you are using Edge, you get the green signal from the Family Safety app, but not if you are using Google Chrome. The issue seems to be affecting mainly Windows 11 devices but Windows 10 or macOS may be affected too. A thread on Microsoft's official Windows forum by Peter Priestley1, which is presumably from an educational institute, says: The thread has been upvoted by 122 people at the time of writing. There are plenty of other such threads online and users also say that they have tried all sorts of things like refreshing cookies and appdata but "nothing" seems to fix it. This shows that Microsoft's safety feature is certainly robust and that it is not easy to bypass but it also means affected users are not too happy about it considering it is seemingly blocking all versions of Chrome. There is one fix that worked though, renaming chrome.exe to something else like chrome1.exe for example. A Chrome community manager, Ellen T, has confirmed that the Microsoft feature is indeed what is causing it and the only way to fix the issue is to "unblock Chrome" inside the Family Safety app. Ellen says: Microsoft has also shared a similar guidance on the issue according to Fred SR., a senior member of the Chrome community.
  • Recent Achievements

    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      660
    2. 2
      ATLien_0
      270
    3. 3
      Michael Scrip
      218
    4. 4
      Steven P.
      162
    5. 5
      +FloatingFatMan
      159
  • Tell a friend

    Love Neowin? Tell a friend!