How to Search trough a database
Moderator: General Moderators
How to Search trough a database
I have a search form and action is pointing to the search.php
How can i search the field "topic name" and/or "topic descrption" ?
Both fields are text type.
thanks!
How can i search the field "topic name" and/or "topic descrption" ?
Both fields are text type.
thanks!
how to check it
How can i check the exact version?
MySQL server is ver 5.0 and PHP 4
MySQL server is ver 5.0 and PHP 4
mysql_query("SELECT topicname, topicdescription FROM <yourtablename> WHERE <put your conditions here>");
So for exemple if you're looking for all the topics post lets say by MrX youd go:
$result = mysql_query("SELECT topicname, topicdescription FROM <yourtablename> WHERE poster='MrX'");
Hope that helps
So for exemple if you're looking for all the topics post lets say by MrX youd go:
$result = mysql_query("SELECT topicname, topicdescription FROM <yourtablename> WHERE poster='MrX'");
Hope that helps
$result = mysql_query("SELECT * FROM <tablename> WHERE <conditions>");
then if you do
$row = mysql_fetch_object($result);
you'll have the data of all the fields in your "object" so if your table has like the fields (id, title, description)
you can access them like this:
$row->id
$row->title
$row->description
or if you prefer using an array instead of an object:
$row = mysql_fetch_array($result);
then you have:
$row['id']
$row['title']
$row['description']
then if you do
$row = mysql_fetch_object($result);
you'll have the data of all the fields in your "object" so if your table has like the fields (id, title, description)
you can access them like this:
$row->id
$row->title
$row->description
or if you prefer using an array instead of an object:
$row = mysql_fetch_array($result);
then you have:
$row['id']
$row['title']
$row['description']
ah wait I missunderstood you!
Well theres no easy way to do it AFAIK, so you should try this:
$result = mysql_query("SELECT * FROM <tablename>");
$num = mysql_num_rows($result);
for($i=0;$i<$num;$i++)
{
$row = mysql_fetch_object($result);
if(stripos($row->description, "video game") != false) //that means video game is in the description
{
//do whatever you want here
}
}
Well theres no easy way to do it AFAIK, so you should try this:
$result = mysql_query("SELECT * FROM <tablename>");
$num = mysql_num_rows($result);
for($i=0;$i<$num;$i++)
{
$row = mysql_fetch_object($result);
if(stripos($row->description, "video game") != false) //that means video game is in the description
{
//do whatever you want here
}
}