bradkenyon Posted August 28, 2008 Share Posted August 28, 2008 I have a download script, and I only want it to run if the id is found in the db table, which refers to the document filename. I think you have to test to see if the number of times it is found, which should be once, since it is a unique id, then it should be a test for if it is larger than 0, then run the script, if not, then display a msg saying no file w/ that id. Here is what I have: <?php include('../cgi-bin/cms/collegeevents/email_function.php'); $docid = $_GET['docid']; if(!$docid == '') { $query = "SELECT * FROM calendar_items WHERE id = '$docid'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { print mysql_num_rows($result); if(mysql_num_rows($result) > 0) { DownloadFile($row['docurl']); print 'downloaded'; } else { print 'no file for that id'; } } } ?> Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 28, 2008 Share Posted August 28, 2008 That's pretty much the way you should go. You can use LIMIT 1 to fetch only one row from the table which will allow you to drop the while($row = mysql_fetch_array($result)) {} loop So: <?php include('../cgi-bin/cms/collegeevents/email_function.php'); $docid = $_GET['docid']; if(!$docid == '') { $query = "SELECT * FROM calendar_items WHERE id = '$docid' LIMIT 1"; $result = mysql_query($query); print mysql_num_rows($result); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); DownloadFile($row['docurl']); print 'downloaded'; } else { print 'no file for that id'; } } ?> Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted August 28, 2008 Author Share Posted August 28, 2008 Thanks, that worked. Modded it a little, to do a check to see if the docid actually has a file associated w/ it. As well if it is a valid id. Now I want to know why whenever I test using a valid id, but the id doesn't has an empty docurl, it prints out "downloaded" and doesn't print out "no file for that id" <?php include('../cgi-bin/cms/collegeevents/email_function.php'); $docid = $_GET['docid']; if($row['docurl'] != '') { $query = "SELECT * FROM calendar_items WHERE id = '$docid' LIMIT 1"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); if($row['docurl']) { DownloadFile($row['docurl']); print 'downloaded'; } else { print 'no file for that id'; } } else { print 'invalid id'; } }?> nevermind, it works. thank you! 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.