Psycho
Moderators-
Posts
12,159 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
Not mad, just trying to get people to think logically and solve thier own problems. That is the essence of programming in my opinion. I have no incentive to people asking questions on this site. I do this for my own benefit. Trying to solve real problems is an activity that helps exercise my mind and it is enlightening to see how others would solve a problem differently than myself. I surely don't want to spend time answering questions that could be answered by a search engine.
-
Didn't a previous poster make the statement that "DATE" might be a reserved word? You then find that when changing from "BY" to "AUTHOR" it starts working. So, wouldn't it be logical to assume that "BY" may be a reserved word? A quick google search would have confirmed that: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html
-
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"; }
-
$todayFile = date('Ymd') . '.pdf';; //Assumes leading zeros are used if file_exist($todayFile) { echo "<a href=\"{$todayFile}\">{$todayFile}</a>\n"; }
-
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
-
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
-
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!!!
-
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.
-
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?
-
I like that better. I always forget about putting additional parameters within for loops like that.
-
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++)
-
<?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; ?>
-
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.
-
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 ?>
-
And where is your current code?
-
What do you think of the new look of these forums?
Psycho replied to smerny's topic in PHPFreaks.com Website Feedback
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. -
search a string within a string and then add another string
Psycho replied to oldtimer's topic in PHP Coding Help
Please mark the topic solved. -
search a string within a string and then add another string
Psycho replied to oldtimer's topic in PHP Coding Help
<?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 ?> -
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"; }
-
[SOLVED] Order array of files made with glob()
Psycho replied to ashton321's topic in PHP Coding Help
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"; } ?> -
[SOLVED] Order array of files made with glob()
Psycho replied to ashton321's topic in PHP Coding Help
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>"; } ?> -
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); ?>
-
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.