Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,685 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,246 people online right now. Registration is fast and FREE... Join Now!




PHP search syntax

 
Reply to this topicStart new topic

PHP search syntax

King8654
post 2 Jun, 2008 - 01:58 PM
Post #1


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 91


My Contributions


lol, lots of little things going to sheet kinda. I had the search box changed on my site, and a button added for a search button instead of default one, and im not sure if that messed it up, but search lil wacked too. i dont know if this does anything, but when hitting submit for search, its just refreshing home.php instead of going to search.php. worked perfect before changing the search box/add jpg button, and been so busy lately havent even had any time to try and pick it apart.

CODE

<?
    require('config.php');
    //echo "This is Search Page";
    if($_POST['Submit']!="Search")
    {
        
        include('home.php');
    }
    if($_SESSION['login']!="true")
    {
        $msg="Gotta Login Before Searching";
        include('home.php');
    }
    else
    if($_POST['Submit']=="search" && $_SESSION['login']=="true")
    {
        $XX = "No Matches Found, Please Search Again";
        $search=$_POST['search'];
        $sql = "SELECT * FROM `topics` WHERE `topic_key` LIKE '%$search%' LIMIT 0, 50";
        $query = mysql_query($sql);
        if(!$query)
        {
            echo mysql_error();
        }
        //echo $sql;
        ?>
        
<table width="500" border="1" cellpadding="2" cellspacing="0" bordercolor="#000033">
  <tr align="center" valign="middle" bgcolor="#CDE4FE">
    <td width="180" height="30" bgcolor="#CDE4FE"><strong><font color="#000033" size="3" face="Tahoma">Category</font></strong></td>
    <td width="150" height="30" bgcolor="#CDE4FE"><strong><font color="#000033" size="3" face="Tahoma">File
      Name</font></strong></td>
    <td bgcolor="#CDE4FE"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Description</strong></font></td>
  </tr>
  <?
        while($row = mysql_fetch_assoc($query))
        
        {
            $variable1=$row["topic_name"];
            $decid=$row["topic_id"];
            $variable2=$row["topic_des"];
            $variable3=$row["sub_id"];
            $q="select * from `subjects` where `id`='".$row["sub_id"]."'";
            $r=mysql_query($q);
            $rw=@mysql_fetch_array($r);
            $category=$rw[1];
            $category=str_replace("-"," >> ",$category);
            $category=str_replace("_"," ",$category);
?>
  <tr align="left" valign="middle">
    <td height="25"> <font size="2" face="Tahoma"> &nbsp;&nbsp;&nbsp;&nbsp;
      <?=$category;?>
      </font></td>
    <td height="25"> <a href=index.php?cmd=browse&&mainsub=<?=$rw[0];?>&&chieldsub=<?=$rw[1];?>&&decid=<?=$decid;?>>
      <font size="2" face="Tahoma">
      <?=str_replace("_"," ",$variable1);?>
      </font> </a> </td>
    <td><a href=index.php?cmd=browse&&mainsub=<?=$rw[0];?>&&chieldsub=<?=$rw[1];?>&&decid=<?=$decid;?>><font size="1" face="Tahoma">
      <?=$variable2;?>
      </font></a></td>
  </tr>
  <?
      }
?>
</table>
<?        //below this is the function for no record!!
        if (!$variable1)
        {
            print ("$XX");
        }

    }
?>


and this is the search box on the index

CODE

<tr>
                      <td align="center" valign="top"><table width="500" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td height="25" align="left" valign="left" bgcolor="#CDE4FE"><font size="2" face="Georgia,Times New Roman,serif" color="#000033">&nbsp;&nbsp;Search
                              Through Exams By Key Subjects, Ideas, Concepts</font></td>
                          </tr>
                          <tr>
                            <td align="center" valign="middle" bgcolor="#CDE4FE"><table width="98%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td align="left" valign="top"><form action="" method="post" name="form1" style="margin-bottom:5px;">
                                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr bgcolor="#E8F2FF">
                                          <td align="left" valign="middle"> <font size="2" face="Georgia,Times New Roman,serif">&nbsp;Enter Topic
                                            Here</font><font size="2" face="Georgia,Times New Roman,serif">&nbsp;</font>
                                            <input name="search" type="text" id="search2" size="48">
                                          </td>
                                          <td width="60" height="30">&nbsp; <input name="imageField" type="image" src="images/button.gif" width="49" height="20" border="0"></td>
                                        </tr>
                                      </table>
                                    </form></td>
                                </tr>
                              </table></td>
                          </tr>


sorry to throw all on you lol, but though id start new topic so i could thank you again for another solution

This post has been edited by King8654: 2 Jun, 2008 - 02:00 PM
User is offlineProfile CardPM

Go to the top of the page

quim
post 2 Jun, 2008 - 02:23 PM
Post #2


D.I.C Head

Group Icon
Joined: 11 Dec, 2005
Posts: 145



Thanked 2 times

Dream Kudos: 350
My Contributions


I don't think the input type image reacts the same way as type submit

EDITED: I should probably mention that this is a JavaScript code
put an onclick event in the input button
CODE
function submitForm()
{
   var formObj = document.getElementByName( "form1" );
   formObj.submit();

}


CODE
<input name="imageField" type="image" src="images/button.gif" onclick="submitForm()" width="49" height="20" border="0">


This post has been edited by quim: 2 Jun, 2008 - 02:44 PM
User is offlineProfile CardPM

Go to the top of the page

King8654
post 2 Jun, 2008 - 03:13 PM
Post #3


D.I.C Head

Group Icon
Joined: 4 Mar, 2008
Posts: 91


My Contributions


so the function should go in the search.php and the imagefield call should go in the index?

sorry m8...ive been messin up the category for posts all day

This post has been edited by King8654: 2 Jun, 2008 - 03:14 PM
User is offlineProfile CardPM

Go to the top of the page

quim
post 2 Jun, 2008 - 04:31 PM
Post #4


D.I.C Head

Group Icon
Joined: 11 Dec, 2005
Posts: 145



Thanked 2 times

Dream Kudos: 350
My Contributions


QUOTE(King8654 @ 2 Jun, 2008 - 07:13 PM) *

so the function should go in the search.php and the imagefield call should go in the index?

sorry m8...ive been messin up the category for posts all day


NO:
the function should go between the head in the index page, "in this case", and it will be called when you press the button.

CODE

<head>
<script type="text/javascript">
/* function goes here
defined before its called in the page input button
*/
</script>
<title><title>
</head>
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:01AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month