matutino Posted November 24, 2008 Share Posted November 24, 2008 Hi everyone, Though I am new to php and mysql, I´ve managed to put up together this code using internet, so I can get my clients to download a different Excell database, depending on their name and people´s countries. I am using personalized php files for each of my clients, with different WHERE commands. I have a database with a variable (Num) which increases automatically with every new information added to my database (when a person leaves a question for my clients in my webpage, and also writes his address, country, city, etc., he gets Num=1, the second person that leaves a question gets Num=2, and so on). What I want to do and I am having trouble with is this: I want to be able to share amongst my clients the questions that have not being specially posted for neither of them. For example, when "Whom" is not 'Myclient1' nor 'Myclient2', I want to distribute the questions based on the unique Num variable attached to each question left on my webpage database. So my idea was to modify this code line in this kind of way (please compare with the original line posted below, with is currently on-line and working, but not doing what I want to do): $query = "SELECT Num, Date, Whom, Name, Email, Country, Nationality, Msg, State, City, Work, Age, Web, ZIP, Phone FROM table WHERE Whom ='Myclient1' AND Country ='Argentina' AND ($Num/10 - intval ($Num/10)) = 1 OR ($Num/10 - intval ($Num/10)) = 2 OR ($Num/10 - intval ($Num/10)) = 3 OR ($Num/10 - intval ($Num/10)) = 4 OR ($Num/10 - intval ($Num/10)) = 5"; By doing this, I want to be able to give Myclient1 the possibility of downloading all questions from Argentina which Num number ends in 1,2,3,4 or 5 (so I divided the Num number by 10, and then substracted the integer part of the number, to remain with a unique digit). I will do something similar with my other client, giving him the 6,7,8,9,0 numbers in other php file, so each client can get his questions without sending the same question to two different clients of mine. Of course, that code that I tried is not working! Can anyone give my a hand with it??? I will greatly apreciate it! Thank you very much in advance! Matt. ----------------------------------------------------------------------------------- ORIGINAL CODE USED ---------------------------------------------------------------------------------- <?php $host = 'localhost'; $user = '123'; $pass = '456'; $db = 'db'; $table = 'table'; $file = 'file'; $FileName = 'name'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $query = "SELECT Num, Date, Whom, Name, Email, Country, Nationality, Msg, State, City, Work, Age, Web, ZIP, Phone FROM table WHERE Whom ='Myclient1' AND Country ='Spain'"; $result = mysql_query($query) or die('Error, query failed'); $tsv = array(); $html = array(); while($row = mysql_fetch_array($result, MYSQL_NUM)) { $tsv[] = implode("\t", $row); $html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>"; } $tsv = implode("\r\n", $tsv); $html = "<table>" . implode("\r\n", $html) . "</table>"; $filename = $file."-".date("d-m_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$filename"); echo $tsv; //echo $html; ?> --------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.