I've a big problem and reading in the web maybe i've found the solution but the logic of it, is too difficult to understand i think :)
I've a table in my mysql database and here it is:
CREATE TABLE eventi (
id INT(12) NOT NULL AUTO_INCREMENT,
autore VARCHAR(100) NOT NULL,
tipo VARCHAR(50) NOT NULL,
titolo VARCHAR(50) NOT NULL,
contenuto VARCHAR(2000) NOT NULL,
data_evento VARCHAR(30) NOT NULL,
fine_evento VARCHAR(30) NOT NULL,
data_finale VARCHAR(40) NOT NULL,
ora_evento VARCHAR(8) NOT NULL,
ora_fevento VARCHAR(8) NOT NULL,
img VARCHAR(255) NOT NULL,
accessi int(10) unsigned NOT NULL default '0',
pagato SET( '0', '1' ) NOT NULL default '0',
pacchetto SET( '1', '2', '3' ) DEFAULT NULL , -- Offerta 1=7gg, 2=14gg, 3=31gg
data DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (id)
);
Ok, the problem is this:
I sell to my clients an events and they pay more or less if they use a type of "pacchetto". You can see from the table that there is a column called "pacchetto" (packet) which could be set to 1, 2 or 3. If they select the first (1), their event will be displayed 7 days before the date (that is "data_finale" - in english: last_date); if they select the second (2), 14 days, and the third (3), 31 days. I've lot of clients and if a client have selected the packet 1 and the event should be online and another client have selected the packet 3 and the event should be online, i have to show both events of both clients. I think its "difficult" however i've done this, but seems dont run, it show me only 1 right event: pastebin . com / RscmQJ7L Thanks for the help!
I advise you to re-write your SQL query. All can be done in 1 query which is much more performant. Just concat your conditions with OR like this:
... WHERE (pacchetto = '1' AND (data_finale >= NOW() AND data_finale <= (NOW() + INTERVAL 7 DAY)) OR
pacchetto = '2' AND (data_finale >= NOW() AND data_finale <= (NOW() + INTERVAL 14 DAY)) OR
pacchetto = '3' AND (data_finale >= NOW() AND data_finale <= (NOW() + INTERVAL 31 DAY))
Not tested but you should get the idea.
I had a similar similar issue when doing a mysql_query within a mysql_fetch. Best avoided. Either do within one SQL statement or bring back query in to an array and then traverse the array. Also, mysql_query is best avoided. Yo should use mysqli or PDO.