Jump to content

seavers

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

seavers's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have tried to read the remote file line by line using php using 'fread', but it still only returns a portion of the file. I have tried usinf cURL, but again only a portion of the remote file is returned. I think it may be a time limit set at the remote end, as I have tested further by reading a larger file from one of my remote servers. So, before I go back to the client and tell them I cannot access the file for a long enough time to download it, am I missing a quicker method access and read the file?
  2. Thank you for your patience fenway. After taking your advice, the following both seem to work: SELECT DISTINCT ( load_id ), COUNT( destination ) FROM `stops` WHERE destination LIKE '%Birmingham%' OR destination LIKE '%Carlisle%' GROUP BY load_id HAVING COUNT( destination ) > 1 SELECT DISTINCT (s1.load_id) FROM stops s1 INNER JOIN stops s2 ON s2.destination LIKE '%Birmingham%' AND s1.load_id = s2.load_id INNER JOIN stops s3 ON s3.destination LIKE '%Carlisle%' AND s2.load_id = s3.load_id ORDER BY s1.load_id I feel happier that my problem can be solved with a single sql query rather than having to call results and not display them. Thanks again.
  3. Ok, if I query the stops table with: SELECT DISTINCT (load_id) FROM `stops` WHERE destination LIKE '%Birmingham%' AND destination LIKE '%Carlisle%' I get no result because a single record only contains one of the destinations. If I use: SELECT DISTINCT (load_id) FROM `stops` WHERE destination LIKE '%Birmingham%' OR destination LIKE '%Carlisle%' I get a result but I also get loads that contain just Carlisle, or just Birmingham. I need to pull results that match both criteria only. Is my logic wrong?
  4. Thanks for replying. Yes, I would like to return unique load_id's. Here's an example, I'll just cut down the freight table info for convenience: I have a record in freight as follows: load_id = 10 start_destination = Bristol end_destination = Edinburgh That freight record also has 2 records ion the stops table associated with it: stop_id = 21 load_id = 10 destination = Birmingham stop_id = 22 load_id = 10 destination = Carlisle I would like to query the database, so that if a search is performed with Birmingham and Carlisle as the search parameters, load_id 10 is returned. I've looked at joins and the union statement, but thety either return a null result or multiple rows.
  5. First of all, sorry for the ambiguos title. I have 2 tables in a database. The first is the main table and is called 'freight'. This records the details of a freight run, and has the following schema: `load_id` int(11) NOT NULL auto_increment, `user_id` int(11) default NULL, `date_from` int(11) default NULL, `date_to` int(11) default NULL, `start_destination` varchar(255) default NULL, `end_destination` varchar(255) default NULL, `full` varchar(4) default NULL, `additional_info` text, `journey_ref` varchar(255) default NULL, `length` int(11) default NULL, `width` int(11) default NULL, `height` int(11) default NULL, `weight` int(11) default NULL, `load_type` varchar(255) default NULL, `vehicle_type` varchar(255) default NULL, `vehicle_load_access` varchar(255) default NULL, `published` smallint(1) default NULL, PRIMARY KEY (`load_id`) Note that the start_destination and end_destination are stored here. I then have another table to store possible stop points inbetween, here's the schema: `stops_id` int(11) NOT NULL auto_increment, `load_id` int(11) default NULL, `destination` varchar(255) default NULL, `destination_date` int(11) default NULL, `dest_length` int(11) default NULL, `dest_width` int(11) default NULL, `dest_height` int(11) default NULL, `dest_weight` int(11) default NULL, PRIMARY KEY (`stops_id`) The user will search a start destination and an end destination, however, these could include destinations in the 'stops' table. For example, the user searches Birmingham as the start destination and Carlisle as the end destination. There is a record for load_id '1' that has 2 stops associated with it in the 'stops' tables, which happen to be Birmingham and Carlisle. How would I construct that query so that I would get one result row returned instead of two or three? Here's a query that I have tried, unfortunately it also returns other results if either one of the two search criteria apply to them: SELECT DISTINCT freight.load_id, user_id, date_from, date_to, start_destination, end_destination, full, length, width, height, weight, load_type, vehicle_type, published FROM freight LEFT JOIN stops ON freight.load_id = stops.load_id WHERE (start_destination LIKE '%Birmingham%' OR end_destination LIKE '%Birmingham%' OR destination LIKE '%Birmingham%') OR (start_destination LIKE '%Carlisle%' OR end_destination LIKE '%Carlisle%' OR destination LIKE '%Carlisle%') AND published = '1' AND date_to >= '1263809728' ORDER BY date_from LIMIT 0, 25 In the short term I have programatically solved the problem by calling the results based upon just the start destination, and then calling another query on the reasult to see if the end destination is included in the results. If it is, the record is shown, if not, then I move onto the next row. However, this seems to be a haphazard way of doing it.
  6. I have read allot of other threads on this, and everyone likes to do things differently. Personally, I always store dates as a timestamp in the database, then convert them back using either the date() or the gmdate() php function. Being UK like me you will probably want to use gmdate() to get a Greenwich Mean Time date.
  7. Hi, Adjusting the memory_limit and execution time seemed to have no effect. I decided not to use fread, and instead used fgets. I thought this would read the remote file in one line chunks, and therefore negate any memory errors. Here's my new code: <?php $handle = fopen("http://www.example.com/largefile.xml", "r"); if($handle) { while (!feof($handle)) { $contents = ''; // set execution time no limit set_time_limit(0); $fp = fopen('c:\\users\\workjames\\xmlinfo.txt', 'a'); $contents = fgets($handle, 4096); // now write to local file // set execution time no limit set_time_limit(0); fwrite($fp, $contents); fclose($fp); flush(); } fclose($handle); } ?> However, this still only returns a prtion of the remote file, a similar amount to before. I don't understand how the memory is being used up (it's set to 128M), can anyone enlighten me? Could it be the size of the file that I'm opening to write the data to? Kind regards, James
  8. I have doubled those values, from 128MB to 256MB but it's still stopping around the same place. I will check some other values and report back.
  9. Hi, I'm attempting to read a large xml file that is held remotely, I'm guessing it's around 250MB in total. I have attempted to use xml_reader to parse the data, but that fails with an XML Error: invalid end of document at around the 65MB mark. So, I attempted to fread the file and write it locally, but that fails around about the same time (65 MB). Here's my simple fread code: $handle = fopen("http://www.example/largefile.xml", "r"); $contents = ''; if($handle) { while (!feof($handle)) { // set execution time no limit set_time_limit(0); $contents .= fread($handle, 8192); } fclose($handle); // now write to local file // set execution time no limit set_time_limit(0); $fp = fopen('xmlinfo.txt', 'w'); fwrite($fp, $contents); fclose($fp); } Should I be able to read and write the whole content of a very large file? If not, what is the best way to get large remote xml files to process locally? Help is much appreciated. James
  10. Thanks Sasa, I tried was trying to use: $row_survey_results['$search'] that's why I turned to the case break. Should have tried: $row_survey_results[$search] which works like a treat.
  11. Works fine for me, is there any space at all between the top of your page and this function?
  12. Hi, I have to search a db table, and count distinct records to get some results from a survey we've done. The record needs to be echoed along with the number of times it is recorded. Each field in the table has to be searched individually, so that we can see the answers for each question separately. I thought that I could do this with one query, maybe 'count distinct', but I couldn't get it to show both the value of the row, and the amount of times that value had been recorded. So, I have to do 2 queries, one getting the distinct values of the field, the other counting how many times they are recorded. Here's the 2 queries: First query: $search = $_POST['search']; mysql_select_db($database_survey, $survey); $query_survey_results = "SELECT DISTINCT * FROM survey group by '$search' having count(*) > 0"; $survey_results = mysql_query($query_survey_results, $survey) or die(mysql_error()); $row_survey_results = mysql_fetch_assoc($survey_results); $totalRows_survey_results = mysql_num_rows($survey_results); Second query: $age = $row_survey_results['age']; mysql_select_db($database_survey, $survey); $query_counting_query = "SELECT * FROM survey WHERE age = '$age'"; $counting_query = mysql_query($query_counting_query, $survey) or die(mysql_error()); $row_counting_query = mysql_fetch_assoc($counting_query); $totalRows_counting_query = mysql_num_rows($counting_query);?> <?php echo $row_survey_results['age']; echo " = "; echo $totalRows_counting_query /228 *100 ?> <br /> <?php } while ($row_survey_results = mysql_fetch_assoc($survey_results)); This works just fine when the variable '$search' value is 'age', but there are 40 or so other questions, so other values for '$search' will be passed, such as 'region'. So I need to select the associative array that is in the second query (row_survey_results['age'] dynamically but I couldn't work out how to do this. In the end I wrote a load of case breaks and the thing works, but instead of 50 or so lines of code I have 1600, so I guess I'm doing it all wrong! The question is 2 part: 1. Could I have puuled the recordset and count in one query? 2. How do you dynamically echo an associative array from a result, i.e. row_survey_results ['dynamic depending on value of $search variable']; Any help would be greatly appreciated, Thanks
  13. Hi, Usually <td align="center"> should work. This is a Joomla site, so maybe some other css style is affecting the positioning of your image (I'm presuming it's the coat of arms image). Try some css: #Layer1 img { margin-right: auto; margin-left: auto; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.