Hello. I am having a hard time building my own search results page for my mysql database. Basically I am trying to search for game categories from the fldCategory field in the table, and display 15 results at a time in an HTML table with the Image of the games (fldIconMedium), and the titles of the games (fldTitle) placed in to the table. Also, at the bottom of the table would have links with numbers that you can click to go to the next set of search results in the same page.
here is a link to show what I mean: http://netroxy.com/51274581336/tablehelp.htm
A simple category search from mysql table?
Moderator: General Moderators
A simple category search from mysql table?
Last edited by Netroxy on Sun Apr 24, 2011 8:44 am, edited 1 time in total.
Re: A simple category search from mysql table?
to grab a certain category of game, you will need to make a query stating the string name of the category that you want to pull out
Re: A simple category search from mysql table?
What have you got so far?
Re: A simple category search from mysql table?
Hello friends. Sorry for not responding sooner. For the code I am using, I had help from another expert. I thank him, but here is the code I have so far.
===========================
===========================
===========================
===========================
To see this code in action, heres the link http://netroxy.com/gameslist.php?cat=skills.
I am expecting the games search results page to look like this: http://netroxy.com/51274581336/search.htm
So basically its:
- viewing how many games found for game category, ex: Skills. Or Action, Mind, etc..
- the URL containing 'gameslist.php?cat=' with the given ID category at the end should search for that given category and display at least 15 games per results, along the number bar bellow, which counts how many are found from that category, which automatically increases or decreases the number bar bellow depending how many games from that specific category was found. I also forgot to mention that I did not add the Previous and Next button, which i dont know how
- As for the 15 results per page, its basically 15 images (fldIconMedium) of different games of the same category, with their Titles (fldTitle) underneath them and both image and title should have the LINK to that specific game. When those 15 results per page are displayed, the link 'http://www.blabla.com/games.php?id=' should be the link for all the title Text links and the image links, and it should add the ID (fldID) next to 'http://www.blabla.com/games.php?id=' for each game category found.
===========================
===========================
Code: Select all
<?php
$cat=1;
$nor=15;
$a=1;
if(isset($_GET['cat']))
{
}
else
{
$_GET['cat']=1;
}
echo $_GET['cat'];
$con=mysql_connect("host","nusername","password")
or die ("error");
$db=mysql_select_db("database",$con)
or die("Database not found!");
$result=mysql_query("SELECT * FROM games")
or die ("query error");
echo "<table border='1'><tr><th>ImageIcon</th><th>Title</th></tr>";
$r=mysql_num_rows($result);
echo $r."<br/>";
$p=ceil($r/$nor);
//echo $p;
while($rows=mysql_fetch_array($result))
{
if($a>($_GET['cat']-1)*$nor)
{
echo "<tr><td>".$rows['fldIconMedium']."</td><td>".$rows['fldTitle']."</td></tr>";
}
$a=$a+1;
}
echo "</table>";
for($i=1;$i<=$p;$i++)
{
if($i==$_GET['cat'])
{
echo $i;
}
else
{
echo "<a href='gameslist.php?cat=".$i."'>".$i."</a>";
}
}
?>===========================
To see this code in action, heres the link http://netroxy.com/gameslist.php?cat=skills.
I am expecting the games search results page to look like this: http://netroxy.com/51274581336/search.htm
So basically its:
- viewing how many games found for game category, ex: Skills. Or Action, Mind, etc..
- the URL containing 'gameslist.php?cat=' with the given ID category at the end should search for that given category and display at least 15 games per results, along the number bar bellow, which counts how many are found from that category, which automatically increases or decreases the number bar bellow depending how many games from that specific category was found. I also forgot to mention that I did not add the Previous and Next button, which i dont know how
- As for the 15 results per page, its basically 15 images (fldIconMedium) of different games of the same category, with their Titles (fldTitle) underneath them and both image and title should have the LINK to that specific game. When those 15 results per page are displayed, the link 'http://www.blabla.com/games.php?id=' should be the link for all the title Text links and the image links, and it should add the ID (fldID) next to 'http://www.blabla.com/games.php?id=' for each game category found.
Last edited by Netroxy on Thu Apr 28, 2011 1:58 pm, edited 1 time in total.
Re: A simple category search from mysql table?
There's your problem. You aren't refining your query at all.Netroxy wrote:Code: Select all
$result=mysql_query("SELECT * FROM games") or die ("query error");
Why not try something like this?Netroxy wrote:Basically I am trying to search for game categories from the fldCategory field in the table, and display 15 results at a time in an HTML table with the Image of the games (fldIconMedium), and the titles of the games (fldTitle) placed in to the table.
Code: Select all
$query = "SELECT fldTitle, fldIconMedium FROM games WHERE fldCategory = {$_GET['cat']} LIMIT 15";
$result = mysql_query($query);Re: A simple category search from mysql table?
please use code tags netroxy