Jump to content

BoarderLine

Members
  • Posts

    140
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BoarderLine's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi. Can someone please point me in the right direction with this. I have the following tables:- table: options | id | sta | fin |valID| |-----|----- |----- |------| | 3 | 984 | 984 | 1 | | 7 | 165 | 685 | 1 | | 5 | 233 | 876 | 1 | table: values | id | col | |-----| -------| | 1 | harry | I am using the following query to attempt to get a joined result set against the key (id), and the MIN(fin) ROW. SELECT values.col, options.id, options.sta, MIN(options.fin) AS fin FROM values JOIN options ON options.valID = values.id GROUP BY options.valID, options.fin ORDER BY col I would like this to result: | col | id | sta | fin | | ----- |----|----- |----- | |harry| 7 | 165 | 685 | However I get the result: | col | id | sta | fin | | ----- |----|----- |----- | |harry| 5 | 233 | 685 | How can obtain the result values for the entire row which contains MIN(fin). Hope this makes sense to someone? Many Thanks.
  2. Hi again. Here is tutorial on file upload and how to use the $_FILES array. http://www.tizag.com/phpT/fileupload.php
  3. Ok. You have options for how to go about this, but probably the best for you would be: Assuming if a Teacher is logged in, they will have some form of userID eg. $_SESSION['userID']. When you create your upload form for the Teachers, have it something like this: <form method="post" enctype="multipart/form-data" action="upload.php"> <label for="lesson">LESSON NAME: <input type="text" name="lesson" id="lesson" /></label><br/> <label for="pdf">LESSON NAME: <input type="file" name="pdf" id="pdf" /></label><br/> <input type="submit" name="submit" value="UPLOAD" /> </form> Now in your upload script (upload.php) you should upload the file into a directory, but at the same time do a mysql insert into a table against the userID of the teacher along with the file name (not the file just the files name), the lesson title. To get the file name use php $_FILES function, the teachers userID should be something like $_SESSION['userID'], and the LESSON NAME $_POST['lesson']. Now you have the .pdf's uploaded into a directory and the lesson information against a teachers userID and lesson title in the db. You can now retrieve from the db a record set of lessons from individual teachers and populate the students list of lessons with the lesson titles as the labels and the file_names as the values. Now when the student selects the lesson from the menu, collect the file name on the form action page as $_POST (like you say), and display it like this on the page. <iframe height='1200' width='100%' src='/path/to/folder/<?php echo $_POST['filename_inputs_name']; ?>'></iframe> And you should be close to what you want.
  4. Is the student selecting the lesson they want from menu of some kind? Can you post the form you are using for for the students selection?
  5. This is perhaps not your php at all. Make sure your domains DNS records are correct.
  6. Might need more info to help on that one. Are you inserting the file name into the db against the users ID on file upload? What sort of user input are you referring to?
  7. What error are getting? Here's a break down of code: $imgDir = "path_to_upload_folder"; -- obvious if(($files = @scandir($imgDir)) && (count($files) > 2)) -- scans the folder where the file is kept and if there are more than 3 items the folder is not empty (3 because it accounts for the . and .. that are present in folders) and the following curly braces are read if($handle = opendir($imgDir)) -- opens the folder so the files can be used while($file = readdir($handle)) -- process the following code for each file that is present in the folder clearstatcache(); -- clear the information that php has cached about the file if(is_file($imgDir.'/'.$file)) -- if the file is present echo "<iframe height='1200' width='100%' src='".$imgDir."/".$file."'></iframe>"; -- open the file in an iframe } closedir($handle); -- close the directory that was opened
  8. You would probably be best to upload the file to a folder on the server. You can open the pdf in a browser by using an <iframe> tag. Use something like this to retrieve it: <?php $imgDir = "path_to_upload_folder"; if(($files = @scandir($imgDir)) && (count($files) > 2)) { if($handle = opendir($imgDir)) { while($file = readdir($handle)) { clearstatcache(); if(is_file($imgDir.'/'.$file)) echo "<iframe height='1200' width='100%' src='".$imgDir."/".$file."'></iframe>"; } closedir($handle); } ?> Hope this helps. Good luck.
  9. And obviously this way the WITH ROLLUP was not needed.
  10. Ta mate. Saved me. Cheers
  11. Thanks silkfire, The problem is I am looping through the data set in a list but need the total sum of 'counter' for the whole data set before the result list is populated. I am trying to avoid doing this in two queries to reduce processing time.
  12. And sorry forgot the essentials: MySQL 4.1.47
  13. I can get the result I need with:- SELECT COUNT(IF(a.field='1',1,NULL)) AS number, b.name FROM b LEFT JOIN a ON a.id = b.id GROUP BY b.name WITH ROLLUP Which results:- henry 6 fred 7 harry 9 terry 0 NULL 22 I can then get the ROLLUP value by using mysql_data_seek() however this makes the rest of the dataset unusable later on the page. I think I may have to move this now to the php forum, unless anyone can share a work around?? Thanks.
  14. Of course, sorry. What I meant to put as example query was this: SELECT COUNT(IF(a.field='1',1,NULL)) AS number, b.name FROM b LEFT JOIN a ON a.id = b.id example result: henry 6 fred 7 harry 9 terry 0
  15. Hi. Is it possible to get the total sum of all count values returned in a query (not total rows of the query but the total sum of a count), but have it returned as a separate variable within the query?. If by using the following query: SELECT COUNT(a.field) AS number FROM a WHERE a.field='1' it returns: 6 7 9 Is it possible to somehow place a variable within the query that will give the value: 22 from the above example?
×
×
  • 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.