Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. As my signature states, I don't always test the code I post here. I typically provide a "logical" solution and leave it up to the posterr to fix any minor typos. $todayFile = date('Ymd') . '.pdf'; //Assumes leading zeros are used if (file_exist($todayFile)) { echo "<a href=\"{$todayFile}\">{$todayFile}</a>\n"; }
  2. $todayFile = date('Ymd') . '.pdf';; //Assumes leading zeros are used if file_exist($todayFile) { echo "<a href=\"{$todayFile}\">{$todayFile}</a>\n"; }
  3. Yes, two. 1. Add an "or die (mysql_error())" to the line where you run your queery so you can see the mysql errors (but I would suggest some 'proper' error handling once it goes to production to prevent users from seeing system errors). 2. What the heck happened to the "ORDER BY"? You have the conditions but not he the actual text for the ORDER BY Try this: SELECT m.id, m.parentId, m.name, c.url, IF(m.id=1, 1, 2) as initOrder FROM menu m JOIN content c ON m.contentId = c.id WHERE m.parentId = 0 OR m.parentId = 1 ORDER BY initOrder ASC, m.order ASC
  4. Assuming that the IDs are numeric - i.e. 1 would come before the others, then you could create a dynamic value that is a 1 (for the first record) or 2 otherwise. Then sort by that value first, then by the 'order' field. Something like this: SELECT *, IF(m.id=1, 1, 2) as initOrder FROM tablename m ORDER BY m.initOrder ASC, m.order ASC
  5. As I suspected you are running a mysql_fetch_assoc() on the query results before the loop starts. So, the first record is always lost. And the variable you assign it to isn't even used anywhere in the script. This is line 6 of your code: $row_RsImage_list = mysql_fetch_assoc($RsImage_list); // ^^^ - That line extracts the first record and does nothing with it!!!
  6. Need to see your PHP code. I suspect you may has misimplemented the code I provided. Perhaps you are doing a mysql_fetch_assoc() before the while loop, which would "use up" the first record before the loop starts.
  7. If cURL isn't supported, then yes you cannot use it. But, just to prevent confusion, cURL does support POST. The "common" use of cURL is to log into another site from the back-end, but it has many different types of uses for interacting with other sites. From the manual
  8. Maybe I missed it, but why can't you use CURL? Seems the best solution to me.
  9. Since I don't have your database, I tested the script using an array. I tested with more than six records, exactly six records, and with less than six records. All of them worked fine. Are you sure there are more than five records returned from the query? Have you checked the rendered HTML to ensure there isn't a character in the query results that might be bungling the HTML?
  10. I like that better. I always forget about putting additional parameters within for loops like that.
  11. Just a tip: It probably doesn't make much different in this particular case (as I assume these are relatively small strings), but it is slower to have the PHP parser continually compute a value in a for loop when you can define the value before hand. In this line for($i = 0; $i != strlen($string); $i++) The parser must compute the length of $string on each iterration of the loop. If the string can change length on each iterration, that would be fine. but, if the string will be 'fixed' for the duration of the loop, then it is considered better form to define a variable with that length $stringLength = strlen($string); for($i = 0; $i < $stringLength ; $i++)
  12. <?php $RsImage_list_rows = 3; // number of rows $RsImage_list_cols = 2; // number of columns $RsImage_list_max = $RsImage_list_rows * $RsImage_list_cols; $RsImage_list_current = 0; // counter $RsImage_list_tableHTML = ''; $RsImage_list_linksHTML = ''; while ($row_RsImage_image = mysql_fetch_assoc($RsImage_list)) { $RsImage_list_current++; if ($RsImage_list_current<=($RsImage_list_max)) { //Add to table output //Create new row (if needed) if ($RsImage_list_current % $RsImage_list_cols == 1) { $RsImage_list_tableHTML .= " <tr>\n"; } //Add image $RsImage_list_tableHTML .= " <td width=\"85\">"; $RsImage_list_tableHTML .= "<a href=\"/images/{$row_RsImage_image['imagename']}\""; $RsImage_list_tableHTML .= " rel=\"lightbox[{$row_RsImage_image['ProductID']}]\">"; $RsImage_list_tableHTML .= "<img src=\"{$row_RsImage_image['imagename']}\" width=\"85\" height=\"64\" border=\"0\"/>"; $RsImage_list_tableHTML .= "</a>"; $RsImage_list_tableHTML .= "</td>\n"; //Close row (if needed) if ($RsImage_list_current % $RsImage_list_cols == 0) { $RsImage_list_tableHTML .= " </tr>\n"; } } else { //Add to links output $RsImage_list_linksHTML .= "<a href=\"/images/{$row_RsImage_image['imagename']}\""; $RsImage_list_linksHTML .= " rel=\"lightbox[{$row_RsImage_image['ProductID']}]\">{$row_RsImage_image['imagename']}</a><br />\n"; } } //Close last row if needed if ($RsImage_list_current % $RsImage_list_cols != 0) { do { $RsImage_list_tableHTML .= "<td> </td>\n"; $RsImage_list_current++; } while ($RsImage_list_current % $RsImage_list_cols != 0); $RsImage_list_tableHTML .= "</tr>\n"; } ?> <table> <?php echo $RsImage_list_tableHTML; ?> </table> <br /> <?php echo $RsImage_list_linksHTML; ?>
  13. To be honest it's not worth my time to try and decypher. It can't be good though. It's probably downloading some code off of their server and running it on yours. Just delete it, find the hole they crawled in through and plug it up.
  14. Well, if the input is a string, then this will work <?php function strToASCII($textStr, $sepStr=' => ', $delimStr=' : ') { $strLen = strlen($textStr); $resultAry = array(); for($i=0; $i<$strLen; $i++) { $resultAry[] = "{$textStr[$i]}{$sepStr}" . ord($textStr[$i]); } return implode($delimStr, $resultAry); } $text = "Test"; echo strToASCII($text); //Output: // // T=>84 : e=>101 : s=>115 : t=>116 ?>
  15. And where is your current code?
  16. I seem to have lost the ability to mark threads as solved or I can't find the link to do so. I was going to say how I didn't link the combining of the replied/viewed data, but you already took care of that Looking better each time I come back.
  17. <?php $content = '<a href="showfile.php?file=helloworld.pdf">PDF Link here'; $content = preg_replace('/(file=[^.]*.pdf)/', '\\1#toolbar=0', $content); echo $content; //Output: // <a href="showfile.php?file=helloworld.pdf#toolbar=0">PDF Link here ?>
  18. You should also add a \n to each line you echo out to preserve the line breaks in the code. Otherwise it makes it very hard to review the output. Also, PRE may cause some unwanted results. So, the other option is to replace all the spaces with non-breaking spaces. I also decided to use file() to read the file into an array. $filename="/tmp/display.cfg"; $linesAry = file($filename) or die("couldn't read file"); foreach ($linesAry as $line) { echo str_replace(' ', ' ', $line) . "<br>\n"; }
  19. In the code I provided, it would create a multi-dimensional array for each file which would include the path and the file modified date. Then there is a small block of code that would order the array. Then you just do a foreach loop to echo the results. As I stated that code was not tested - but the logic was sound. I fixed a few minor errors and it works fine now. Give this a try: <?php $query = mysql_query("SELECT * FROM galleries"); $result = mysql_fetch_array($query); $result['galname']; $files = array(); foreach(glob("../webdev/images/galleries/$galname/*") as $file) { if(is_file($file)) { $files[] = array( 'path' => $file, 'name' => basename($file), 'date_modified' => filemtime($file) ); } } //Order the array by date modified function sortByModified() { if ($a['date_modified'] == $b['date_modified']) { return 0; } return ($a['date_modified'] < $b['date_modified']) ? -1 : 1; } usort($files, 'sortByModified'); //print the results echo "<a href=\"../scripts/phpThumb.php?src={$files[0]['path']}&h=400&w=400\" rel=\"lightbox-{$galname}\" >"; echo "<img src=\"{$files[0]['path']}\"</a><br /><br />\n"; foreach ($files as $file) { echo "<a href=\"../scripts/phpThumb.php?src={$file['path']}&h=400&w=400\" rel=\"lightbox-{$galname}\" >{$file['name']}</a><br />\n"; } ?>
  20. Not tested: <?php $query = mysql_query("SELECT * FROM galleries"); $result = mysql_fetch_array($query); $galname = $result['galname']; $files = array(); foreach(glob('../webdev/images/galleries/$galname/*') as $file) { if(is_file($file)) { $files[] = array( 'path' => '../' . ltrim($file, '../webdev/'), 'date_modified' => filemtime($file); ); } } //Order the array by date modified function sortByModified() { if ($a['date_modified'] == $b['date_modified']) { return 0; } return ($a['date_modified'] < $b['date_modified']) ? -1 : 1; } usort($files, 'sortByModified'); //print the results echo "<a href=\"../scripts/phpThumb.php?src={$files[0]['path']}&h=400&w=400\" rel=\"lightbox-{$galname}\" > echo "<img src=\"../scripts/phpThumb.php?src={$files[0]['path']}&h=200&w=200\"</a>"; foreach ($files as $file) { echo "<a href=\"../scripts/phpThumb.php?src={$file['path']}&h=400&w=400\" rel=\"lightbox-{$galname}\" ></a>"; } ?>
  21. This is not tested , but the logic should be right <?php //This function processes the import file and returns an array in the format //array( // ['L-00001025'] => 'FRIDAY ZONE', // ['L-00001067'] => 'NATURAL HERITAGE OF INDIANA', // ['L-00001078'] => 'NATURAL HERITAGE OF INDIANA' //) function importFile($filePath) { $output = array(); $lines = file($filePath); foreach($lines as $line) { list($code, $value) = explode('|', $line); $output[$code] = $value; } return $output; } //This function will output // - ALL value if no search value is passed // - All values that match a single search value passed as a string or an array // - All values that match multiple search values passed as an array function displayResults($resulAry, $search=false) { if ($search !== false) { if(is_string($search)) { $outputAry = $resulAry[$search]; } elseif(is_array($search)) { $searchKeys = array_fill_keys($search, ''); $outputAry = array_intersect_key($resulAry[$search], $searchKeys); } } else { $outputAry = $resulAry; } echo "<table> "; foreach($outputAry as $code => $value) { echo "<tr><td>{$code}</td><td>{$value}</td></tr> "; } echo "</table> "; } //Example usage $data = importFile('names.txt'); echo "<br>Here are the records for the code 'L-00001067':<br> "; displayResults($data, 'L-00001067'); echo "<br><br>Here are the records for the codes 'L-00001067' & 'L-00001067':<br> "; $searchAry = array('L-00001067', 'L-00001067'); displayResults($data, $searchAry); echo "<br><br>Here are ALL the results for 'L-00001067':<br> "; displayResults($data); ?>
  22. How would I go about doing that? That has always worked for me in the past. :S Really? Try echoing $crewchk or $crewboss to the page. You will get something like "Resource ID #17". You have to extract the values from the result set using one of the mysql_fetch function or similar functions. The id value is automatically incremented in my db so I don't need to add a value. So, don't include it in the list of fields to be populated as demonstrated in my examples. You don't have to list fields that have default values which you want populated with the default - kind of the point of a default value.
  23. I see a few potential problems: $crewchk = mysql_query("SELECT crew FROM users WHERE username='$username'"); $crewboss = mysql_query("SELECT owner FROM crews WHERE owner='$owner'"); You run those two queries and assign the results to those two variable. THEN you try and use those two variable in an INSERT query. Those variables are not values, they are resource IDs to the result fo the queries. You need to extract the values. mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id` ) VALUES ( '', '$crewboss', '$username', 'You have a member ready to be promoted to $newrank! Let him rank?', '$date', '0', '0', '0' )"); Why include `id` in the INSERT if you are not going to provide a value? }elseif ($crewchk == "0"); mysql_query("UPDATE users SET rank='$newrank' WHERE username='$username'"); Not even sure what that is supposed to do. You have a semicolon after the elseif clause so the elseif ends there and all code after it will be run without regard to the else if. You should format your code with some structure and add error handling/checking to find errors easier. The example below uses an "or die()" on the queries. It is fine for quick validations but shoudl not be included in your final code. I prefer to build my own query error handler to prevent error messages going to the user with technical data. <?php if (!$done) { $done="0"; } if ($done == "1") { $query = "SELECT crew FROM users WHERE username='$username'"; $result = mysql_query($query) or die ("Error:<br>".mysql_error()."<br><br>Query:<br>$query"); $crewchk = mysql_result($result, 0, 'crew'); $query = "SELECT owner FROM crews WHERE owner='$owner'"; $result = mysql_query($query) or die ("Error:<br>".mysql_error()."<br><br>Query:<br>$query"); $crewboss = mysql_result($result, 0, 'crew'); $query = "INSERT INTO `inbox` (`to`, `from`, `message`, `date`, `read`, `saved`, `event_id`) VALUES ('$crewboss', '$username', 'You have a member ready to be promoted to $newrank! Let him rank?', '$date', '0', '0', '0')"; $result = mysql_query($query) or die ("Error:<br>".mysql_error()."<br><br>Query:<br>$query"); } elseif ($crewchk == "0") { $query = "UPDATE users SET rank='$newrank' WHERE username='$username'"; $result = mysql_query($query) or die ("Error:<br>".mysql_error()."<br><br>Query:<br>$query"); $query = "INSERT INTO `inbox` (`to`, `from`, `message`, `date`, `read`, `saved`, `event_id`) VALUES ('$username', '$username', 'You have been promoted to $newrank your doing well!', '$date', '0', '0', '0')"; $result = mysql_query($query) or die ("Error:<br>".mysql_error()."<br><br>Query:<br>$query"); } ?>
  24. Hard to say without seeing the "actual" query and the error that is generated.
×
×
  • 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.