Borderline Posted November 21, 2009 Share Posted November 21, 2009 I've been trying to generate a php include, using data from my database, but am not getting the effect I was expecting. The current result can be found at: http://www.equinefocus.co.uk/random/0345gdfg/trialcode.phpThe code currently in use is: <?php $data = mysql_query ("SELECT * FROM ***** WHERE ref='001'"); while($info = mysql_fetch_array($data)) { // data $url='/random/0345gdfg/filters/'.$info['url']; $addstats='/random/0345gdfg/filters/'.$info['urla']; ?> <table border="1" cellpadding="5" cellspacing="0" width="50%" align="center"> <tr> <td width='60%' bgcolor='silver'><a href="<?php echo $url;?>"><?php echo $info['filter']; ?></a></td> <td width='40%'><?php include($addstats);?></td> </tr></table><?php} ?> I attach a pdf file showing a small section of my database: http://www.equinefocus.co.uk/random/0345gd...rs/20091121.pdf. The PHP include file pulls in stats for each filter, code of which is below. <?php include($_SERVER['DOCUMENT_ROOT'].'/random/0345gdfg/*****.php');?><table border="0" cellpadding="2" cellspacing="0" width="100%"> <td width="25%"><?php $query = "SELECT SUM(profit) FROM *****"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo $row['SUM(profit)']; echo "<br />"; } ?></td> <td width="25%"><?php $query = "SELECT COUNT(horse) FROM ***** WHERE pos ='1'"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo $row['COUNT(horse)']; echo $row['type']; echo "<br />"; } ?></td> <td width="25%"><?php $query = "SELECT COUNT(horse) FROM *****"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "Number of qualifers:". $row['COUNT(horse)'] ." ". $row['type'] .""; echo "<br />";}?></td> </tr></table> If there are better ideas on how I can generate this information in a more effective manner, please do let me know! Link to comment Share on other sites More sharing options...
justsomeguy Posted November 23, 2009 Share Posted November 23, 2009 I'm confused about what you're trying to do, are you trying to generate include files on the fly? If so, why? Link to comment Share on other sites More sharing options...
Borderline Posted November 23, 2009 Author Share Posted November 23, 2009 Yes - I have 150+ filters to put on the data I have, and I thought it would be easier to control/edit filters if they were includes.I am aiming for a list of the filter names, the number of winners (WHERE res=1) and the number of qualifers (count number of rows) for each filter so that I can scroll down the list of filters and see the profit/loss for each filter without having to click to a new page.How would you suggest achieving this? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 23, 2009 Share Posted November 23, 2009 Are you having PHP actually create these include files, or do you create them yourself? Can you show the code in one of the includes? I'm confused about how you're filtering the data, does the include file actually get the data that the parent uses? Link to comment Share on other sites More sharing options...
Borderline Posted November 23, 2009 Author Share Posted November 23, 2009 The second box in my original thread is a sample of the include - basically the WHERE data etc will alter depending on the filter.Therefore, there is a column called tfr, which has a result of 1,2 or 3. Therefore, I wish to produce a list of filters from the table WHERE tfr = each of these numbers. And so on.Thanks for your attention on this, appreciate it's a complex idea (not helped by a relative newcomer going out of their depth!) Link to comment Share on other sites More sharing options...
justsomeguy Posted November 23, 2009 Share Posted November 23, 2009 Ah, when I saw this in that code:<?php include($_SERVER['DOCUMENT_ROOT'].'/random/0345gdfg/*****.php');?>I assumed the include file was still somewhere else.Instead of having your filters actually output any HTML, it will probably be best to just have them return data about the filter to the parent page and then the parent will run the actual report and display it. Your filter file could define things like various SQL statements the parent should run, the name of the filter, etc, and the parent page would include the file, get all of that data, and run the queries or do whatever. That way your parent could include all of the filters to display info about them without running the report 150 times. Link to comment Share on other sites More sharing options...
Borderline Posted November 23, 2009 Author Share Posted November 23, 2009 Sounds ideal - any advice on where I can read up on achieving this? I've googled several ideas previously, but not knowing what I'm looking for complicates matters somewhat. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 23, 2009 Share Posted November 23, 2009 It's probably best to create an array to store all of the data in. I'm not sure what data you need to return about each filter, but the include file might just define an array like this: $filter_data = array( 'name' => 'Filter 1', 'record_sql' = 'SELECT * FROM table WHERE ref=\'001\'', 'count_sql' = 'SELECT COUNT(*) AS num FROM table WHERE ref=\'001\''); So after including that, you could run the $filter_data['record_sql'] query to get the records, or the $filter_data['count_sql'] query to return a count of records that match the filter. You could also define things like the table name the records are coming from, or the list of conditions in the WHERE clause, the list of field names returned by the record query, etc. It just depends what data you want about each filter.You might also be able to use SQL Views or Stored Procedures to help with this. Link to comment Share on other sites More sharing options...
Borderline Posted November 26, 2009 Author Share Posted November 26, 2009 Many thanks for your help, I'll look into it! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.