"search" database and display results on website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rlgriffo
Forum Newbie
Posts: 4
Joined: Sun Aug 03, 2008 1:44 am

"search" database and display results on website

Post by rlgriffo »

Hi, I am a complete newbie to PHP & mysql.

I have created a database for my website...i want to be able to search the database for a keyword eg "hairdresser" and for it to return all the entries which include this keyword. I don't want people to see a search box or anything, i just want the results to be sitting there for them when they open that page.

I have learnt what i know so far (not much) from online tutorials, however i cant seem to find any information on how to display the data i have in my table in this manner.

If anyone could help me, provide me with some code or direct me to a online tutorial or something i would really appreciate it.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: "search" database and display results on website

Post by Dynamis »

rlgriffo wrote:I don't want people to see a search box or anything, i just want the results to be sitting there for them when they open that page.
Well you need to pass a keyword to mysql to search for, so where do you plan on putting this in? Hardcoding it into each page (ie. bike.php would display all the bike info in the database, car.php would display all the car info in the database)?

You could always do this with GET, ie.:
info.php?item=bike would display all the bike info on info.php
info.php?item=car would display all the car info on info.php

Sessions are an option. Just need more information on how you want this done.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: "search" database and display results on website

Post by Chalks »

I think the way I would do this (if I'm understanding you correctly) is at the top of the page that I want to display hairdresser information I would do this:

Code: Select all

<?php
$askingFor = "hairdresser";
?>
Then later on when I actually want to display the information, I would create a query

Code: Select all

<?php
$sql = "SELECT $askingFor FROM mytable";
$result = mysql_query($sql) or die(mysql_error());
while($data = mysql_fetch_assoc($result))
  doStuff($data['$askingFor']);
?>
rlgriffo
Forum Newbie
Posts: 4
Joined: Sun Aug 03, 2008 1:44 am

Re: "search" database and display results on website

Post by rlgriffo »

So Sorry i didnt reply sooner after you spent your time replying....


My database is a database of businesses - hairdressers, bakeries, butchers, petshops all in together.

My database has several columns business_name, industry, address, phonenumber, email, suburb, information etc

I would like my website to have a home page --->businesses (they will choose a business category from a list of links eg hairdressers)----->a page showing a table of all of the hairdressers in the database showing their Name and Suburb one after the other. Basically the "Industry" and "Keywords" entered into the database will determine which category the hairdresser appears under.

Then I want people to be able to click on the hairdresser they want more info on and be taken to a screen with MORE of that particular hairdresser's details that I have entered in the database....eg name, address, phone number, email, information, images etc.

Is this possible?

:) Thank you

Sorry i didnt get back sooner.
Post Reply