Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Search Engine in PHP?

Posted on 2000-04-03
5
Medium Priority
?
201 Views
Last Modified: 2008-03-06
I am trying to create a search engine on my site (Recruitment) where candidates can look for jobs.

I am getting the results. But I want to limit the number of jobs that can be viewed per page. I have decided on four jobs per page.

I am therefore able to get the number of pages that need to be generated. But What do I do after that?

I want to create it something like the search in Altavista.com

Looks something like this:

[<< Prev] 1 2 3 4 5 etc.. [Next >>]

Awaiting your reply..
Shireen:)
0
Comment
Question by:shireen_shabbir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:us111
ID: 2679195
Which database do you use ?
0
 

Author Comment

by:shireen_shabbir
ID: 2679227
MySQL
0
 
LVL 8

Accepted Solution

by:
us111 earned 300 total points
ID: 2679293
So, your query could look the following:

$query="select * from table LIMIT 4;"; //  # Retrieve the first 4 rows
$query="select * from table LIMIT 4,4;"; //  # Retrieve rows 5-9

LIMIT n is equivalent to LIMIT 0,n.
If one argument is given, it indicates the maximum number of rows to return.
0
 

Author Comment

by:shireen_shabbir
ID: 2679735
I am in a little trouble here. I dont know how to explain so I am putting a bit of the code:

<table width=100% cellspacing=0 cellpadding=0>
        <tr>
              <td width="15%"></td>
                <td bgcolor="#67A0BA" width="70%">
                <?
                     $mysql_link=mysql_connect("localhost", "root", "");
                     mysql_select_db("Recruit", $mysql_link);
                     
                     if ($Title == "0" & $Skill == '0' & $Location == "0" & $JobPreference == "0")
                     {
                           $query="select * from tblJob";
                     }
                     if ($Title == "0" & $Skill != '0' & $Location == "0" & $JobPreference == "0")
                     {
                           $query="select * from tblJob, tblJobSkill where ";
                           $query2="select SkillID from tblSkill where SkillName='".$Skill."'";
                  $mysql_res=mysql_query($query2, $mysql_link);
                        
                  $num=mysql_fetch_row($mysql_res);
                        
                  $query .= "tblJob.JobID=tblJobSkill.JobID and tblJobSkill.SkillID='$num[0]' and tblJob.Title like '%%' and tblJob.Location like '%%' and tblJob.JobPreference like '%%'";
                 }
                     else
                     {                                       
                           $query="select * from tblJob where ";
                  
                  if ($Title == "0")
                  {
                        $query .= "tblJob.Title like '%%' and ";
                  }
                  else
                  {
                        $query .= "tblJob.Title='".$Title."' and ";
                  }                                    
                  if ($Location == "0")
                  {
                        $query .= "tblJob.Location like '%%' and ";
                  }
                  else
                  {
                        $query .= "tblJob.Location='".$Location."' and ";
                  }
                  if ($JobPreference == "0")
                  {
                        $query .= "tblJob.JobPreference like '%%'";
                  }
                  else
                  {
                        $query .= "tblJob.JobPreference='".$JobPreference."'";
                  }
                     }
                     
                 $mysql_result=mysql_query($query, $mysql_link);                
                 
                 $numrow=mysql_num_rows($mysql_result);
                     
                       print("\n<form id=jobresult method=post action=\" \">\n");
                 print("<BR>");
                 print("<table width=75% cellspacing=0 cellpadding=0><tr><td class=td><b>Check if desired</b></td><td class=td align=center><b>Job Details</b></td></tr></table>");
                 
                 $numview=4;
                 $i=$lowernum;                
                       while (($row=mysql_fetch_row($mysql_result)) & ($i < $highernum))
                 {
                            print("\n<BR>\n");
                            print("\n<table class=tableborder width=100% border=3><tr><td>");
                            print("\n<table border=0 cellspacing=0 cellpadding=0 width=100%>\n");
                            
                            print("\n<tr><td align=center>&nbsp;<input type=checkbox size=15 value=$row[0]>&nbsp;</td>\n");
                      
                       print("\n<td class=boldsmallfont>Job Title: </td>\n");
                       print("\n<td class=td colspan=2>$row[1]</td><td></td></tr>\n");
                      
                       print("\n<tr><td></td><td class=boldsmallfont>Position: </td>\n");
                       print("\n<td class=td colspan=2>$row[2]</td><td></td></tr>\n");
                      
                       print("\n<tr><td></td><td class=boldsmallfont>Job Preference: </td>\n");
                       print("\n<td class=td colspan=2>$row[3]</td><td></td></tr>\n");
                      
                       print("\n<tr><td></td><td class=boldsmallfont>Location: </td>\n");
                       print("\n<td class=td colspan=2>$row[4]</td><td></td></tr>\n");
                      
                       print("\n<tr><td colspan=4>&nbsp;</td></tr>\n");
                      
                       print("\n<tr><td></td><td class=boldsmallfont>Last Date for Applications: </td>\n");
                      
                       $query2="select date_format('$row[13]','d/m/y')" ;
                           $mysql_result2=mysql_query($query2, $mysql_link);
                      
                       $rec=mysql_fetch_row($mysql_result2);
                       print("\n<td class=td>$rec[0]</td>");
                       print("<td align=center>");
                       print("<table border=3><tr><td align=center class=td bordercolor=#aaaaaa bgcolor=#aaaaaa>");
                       print("<a href=# onClick=\"window.open('description.php3?JobID=$row[0]', 'Description', 'scrollbars,width=700 height=500');\">");
                       print("Show Details</a></td></tr></table></td></tr>");
                                             
                       print("\n<tr><td colspan=4>&nbsp;</td></tr>\n");
                      
                       print("\n</table>\n");
                       print("\n</td></tr>\n</table>\n");
                       $i += 1;
                 }
                 
                 if ($numrow > 4)
                 {
                       print("<table align=center cellspacing=0 cellpadding=5><tr>");
                       print("<td class=td>Pages</td>");
                      
                       $numpage=$numrow/$numview;
                       $numex=$numrow%$numview;
                      
                       if ($numex > 0)
                       {
                             $numpage += 1;
                       }
                       for ($j=1; $j <= $numpage; $j++)
                       {
                             print("<td><A href='jobresult.php3?lowernum=$lowernum&highernum=$highernum&Title=$Title&Location=$Location&Skill=$Skill&JobPreference=$JobPreference'>$j</A></td>");                             
                       }
                       print("</tr></table>");
                 }
                ?>
                </form>
            </td>
                <td width=15%></td>
      </tr>
</table>
************************************

When I add "Limit" to the Select statement, it does not give me the total number of results. In this case, it just gives me four records.

So I have tried to do that by adding it to the while statement. Yet it doesnt work..


Please help me out..

Awaiting ur reply



Thanks in adv.
0
 
LVL 8

Expert Comment

by:us111
ID: 2679915
Yes with the limit command you can't get the total number of rows
What you can do is to create 2 query.

<?
$query = "select * from table";
$mysql_result=mysql_query($query, $mysql_link);      
$numrow=mysql_num_rows($mysql_result);

......
and then the query with limit

In term of performance, I don't think it will slow your system :)
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question