CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`btype` int(8) NOT NULL DEFAULT '4',
`type` varchar(127) NOT NULL,
`title` text CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`xrl` varchar(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `xrl` (`xrl`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
There are many Tutorials on selecting and displaying data, try the following search:
The mysql_* extension is deprecated as of version 5.5 and is being removed as of version 7 of PHP (which is due to come out later this year). @laflair13 you’re better off googling for tutorials that use PDO
The question is how to construct SQL query? Or how to execute it from PHP? Or both?
Clarify it please. I can help with the answer but i don’t want to do useless work answering the wrong question
-- phpMyAdmin SQL Dump
-- version 4.3.8
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 13, 2015 at 08:00 AM
-- Server version: 5.5.40-36.1
-- PHP Version: 5.4.23
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `tmcguire_database`
--
-- --------------------------------------------------------
--
-- Table structure for table `new_equip`
--
CREATE TABLE IF NOT EXISTS `new_equip` (
`id` int(11) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`itemname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`desc` varchar(12000) COLLATE utf8_unicode_ci NOT NULL,
`condition` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`category` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`image` longblob,
`owner` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
) ENGINE=MyISAM AUTO_INCREMENT=235 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `new_equip`
--
ALTER TABLE `new_equip`
ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `id` (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `new_equip`
--
ALTER TABLE `new_equip`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=235;
And what I am trying to do is display the item on my frontend based on Category and Condition. Like New Car, or Used Truck. I know how to do it with just one. I use the code below to do that.
include_once('mysql_connect.php');
$Amt = 20;//Amount per page
$Cat = $_GET['Cat'];
$Page = @$_GET['Page'];
$SQLCat = "";
if (strlen($Cat) > 1)
{
$SQLCat = "AND (`Category` LIKE '$Cat;%' OR `Category` LIKE '%;$Cat' OR `Category` LIKE '$Cat')";
}
$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE (`condition`='New' OR `condition`='Excellent' OR `condition`='Very Good') $SQLCat $Limit";
$R_GetEquipment = mysql_query($SQL_GetEquipment, $Link);
I’m still not sure i’m getting it right.
You want to filter items with category and condition?
As i see you have already done categories filter.
So why can’t you just add another variable and put in into your query?
I mean something like this:
$cond = $_GET['cond'];
$SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE (`condition`='$cond') $SQLCat $Limit";
PS: Are you store categories data in a single field? That’s very bad practice. You should use one-to-many relation. Learn about it here.