Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Before you look into caching you need to first solve the problem of how you are extracting the data. For each category and another for topics in that category. You can get ALL of that data with a single query! I'll take a look at the code and see if I can provide a solution. At the very least I'll provide a method to point you in the right direction. It is difficult sometimes to reverse engineer someones code.
-
You should almost never, ever need to do queries within loops: You should start here. Instead of doing sub-queries for each subcategory your first query should return all categories AND all subcategories in one query. Then process the records within PHP to display the categories and subcategories appropriately. Although, from your description I am not understanding this statement: Your statements seem to suggest you are running one query to get the main categories So why do you have 15 queries just to get the parent categories?
-
Can't do it with what you provided. I assumed there are three tables: users, posts and forums. You stated the posts table included an id to the forum. Just replace "users", "posts" and "forums" with the respective table names. Don't forget to change the field names to their respective values as well. Red = table names, blue = field names
-
Not knowing the exact table and field names, this is just an example: $query = "SELECT u.username, u.userid, f.forumname, COUNT(f.forumid) as forumcount FROM users u JOIN posts p ON u.userid = p.userid JOIN forums f on p.forumid = f.forumid GROUP BY f.forumid WHERE u.userid = $userID";
-
By the way, that logic is still flawed. It assumes that if the folder exists that the file exists as well. Why not just check for the file directly instead of just the folder? Plus, you are already defining the $destination and then hard-coding the file path in the IF condition. Way too much work and prone to errors. Use your variables. Also, you have two scenarios where the destination file is displayed. Are you planning on really echo'ing that other text? If not, then the logic can be rewoirked to be more efficient. <?php $source_file = "users/progress_clean.php"; $destination_folder = "users/{$session->username}"; $destination_file = "{$destination_folder}/progress.php"; if (!file_exists($destination_file)) { //Attempt to copy source file if(!mkdir($destination_folder, 0700)) { echo "The specified folder could not be created. Please try again.\n"; } elseif(!copy($source_file, $destination_file)) { echo "The specified file could not be copied. Please try again.\n"; } } //Only include if already present or it copy was successful if (file_exists($destination_file)) { include ($destination_file); } ?>
-
I see one glaring problem: $filename = 'users/$session->username'; You are defining the variable with single quotes which means variables int he string are not interpreted.
-
If you had taken the time to identify that in your first post instead of specifically stating you had two arrays you would have samed me a lot of time. I love to help, but when I provide a solution to what someone asks and then the requestor changes the requirements it tells me the person does not appreciate the the time and effort we take to provide help. I'll make the assumption that it was an honest oversight - this time. <?php function custom_merge($inputAry) { $outputAry = array(); $key2List = array(); foreach($inputAry as $key1 => $data1) //key1 = UB { $key2List = array_keys($data1); foreach($data1 as $key2 => $valuesAry) //key2 = 0, -1 { foreach($valuesAry as $key3 => $value) //key3 = 1070, 1079 { if(!isset($outputAry[$key1][$key3])) { //Fill the $key3 subarray will all 0 values for all $key2 instances $outputAry[$key1][$key3] = array_fill_keys($key2List, 0); } $outputAry[$key1][$key3][$key2] = $value; } } } return $outputAry; } $ary = array( 'UB' => array( 0 => array( 1070 => 750000.00, 1079 => -750000.00 ), -1 => array( 1079 => -450000.00 ) ) ); echo "<pre>"; print_r(custom_merge($ary)); echo "</pre>"; ?>
-
$theArray = array ( 0 => array ( 'q_id' => 1, 'q_v_id' => 857434, 'q_session' => fe13c9e53d1e6d0170a59f88c6327547 ) ); print_r($theArray);
-
I'm sure there is probably a more efficient method, but this will work. I would give the varaibles more descriptive names as to what the values represent. But since I have no idea what the values are I used $key1, $key2, etc. <?php function custom_merge($inputArrays) { $outputAry = array(); $key2List = array(); //Reverse keys 2 and 3 foreach($inputArrays as $inputAry) { foreach($inputAry as $key1 => $data1) //key1 = UB { foreach($data1 as $key2 => $data2) //key2 = 0, -1 { if(!in_array($key2, $key2List)) { $key2List[] = $key2; } foreach($data2 as $key3 => $value) //key3 = 1070, 1079 { $outputAry[$key1][$key3][$key2] = $value; } } } } //Insert 0 values where needed foreach($outputAry as $key1 => $data1) { foreach($data1 as $key3 => $data2) { foreach($key2List as $key2) { if(!isset($outputAry[$key1][$key3][$key2])) { $outputAry[$key1][$key3][$key2] = 0; } } } } return $outputAry; } $ary1 = array( 'UB' => array( 0 => array( 1070 => 750000.00, 1079 => -750000.00 ) ) ); $ary2 = array( 'UB' => array( -1 => array( 1079 => -450000.00 ) ) ); echo "<pre>"; print_r(custom_merge(array($ary1, $ary2))); echo "</pre>"; ?> Output: Array ( [uB] => Array ( [1070] => Array ( [0] => 750000 [-1] => 0 ) [1079] => Array ( [0] => -750000 [-1] => -450000 ) ) )
-
1. Do not bump a post after just 15 minutes. The reason most posts don't get a quick (or good) respons is due to the lack of providing th correct information. 2. That code above tells us nothing about what the problem is. That code above would produce a single select list with jsut one optino. So, you obviously have not provided the relevant information for anyone to respond thoughtfully. Where is the code for the query and extracting the data?
-
Hmm, this would seem to allow for the same functionality without all that code and doesn't even require a daatabase. Just pop all the users into an array and the array order is determine each week automatically using date('W'): //Array of all users $userStack = array('User1', 'User2', 'User3'); //Reorder array for current week for($idx=0; $idx<(date('W')%count($userStack)); $idx++) { array_push($userStack, array_shift($userStack)); } print_r($userStack);
-
Somewhere on the file system ther is a folder named "root". The folder in which THAT folder exists is the actual root.
-
You need to name the select field so it is interpreted by PHP as an array, i.e. you need to add brackets to the name <select name="fieldname[]"> The value $_POST['fieldname'] will be available in the receiving page and will be an array of all the selected values.
-
OK, the "root" for the website (i.e. http://www.mysite.com) is in the public_html, but that is not necessarily the root of the file system! Run this file and you will see where the system root is: echo "<pre>"; print_r(glob('/*')); echo "</pre>";
-
I always seem to get these backwards, but with the slash at the beginning of the path it indicates that the path should be relative from the root of the site. Without the slash the path should be relative from the current location/path. If that is not what you are seeing, then it is the opposite.
-
Well, there is obviously some problem in that file. Does it work if you access it directly? What is in that file? I would take a look at any header commands it might have.
-
Connecting to MySQL database but not returning anything
Psycho replied to Merriick's topic in PHP Coding Help
I noticed I had a typo in the two places that I used mysql_num_rows(). You shuld correct that if you are going to use that code. -
Connecting to MySQL database but not returning anything
Psycho replied to Merriick's topic in PHP Coding Help
Well, off hand the only thing that comes to mind is that the result may have different field names then the ones you are trying to access. For example, the case of the letters is important ("subject" != "SUBJECT"). But, I would also suggest some changes to that logic. 1. $query=("SELECT * FROM phpc_uid"); Typically, you should refrain from using "*" as your select criteria unless you need all the data because it uses up additional resources and can be a performance issue on high-traffic sites. Plus, depending on how the data is used it could cause a security problem if fields are added in the future. Besides in this example you are only using two fields, so you should only query for those two. 2. while ($i < $num) { It really makes no sense to define the number of rows returned and then use a counter to get those rows. Just use a while loop that extracts each row. 3. The select query has no error handling, so that could be failing. Example: <?php $link = mysql_connect("$dbServer1", "$dbUser1", "$dbPass1") or die("Could not connect post"); echo "Connected successfully to $dbServer1 Server<br>\n"; mysql_select_db("$dbName1") or die("Could not select database your_db_name1"); echo "Database $dbName1 selected successfully<br><br><br>\n"; $query = "SELECT subject, description FROM phpc_uid"; //$query = "SELECT * FROM phpc_uid"; //DEBUG LINE $result=mysql_query($query); //$firstrow = mysql_fetch_assoc($result); //DEBUG LINE //print_r($firstrow); //DEBUG LINE //exit(); //DEBUG LINE if(!$result) { //Error running query echo "The query failed.<br /><br />\n"; echo "Query: {$query}<br /><br />\n"; echo "Error: " . mysql_error(); } elseif(mysql_numrows($result)<1) { //No results from query echo "No results returned\n"; } else { //Results were returned, show results $num_rows = mysql_numrows($result); echo "Number of rows returned: {$num_rows}<br /><br />\n"; while ($row = mysql_fetch_assoc($result)) { echo "{$row['subject']} and {$row['description']}<br />\n"; } } If you don't get the results you expect, uncomment the debug lines to validate what is returned/available in that table. -
It seems the forum screwed with the code in trying to convert the code to a smiley. As for the transparency, the code should only work on a jpeg (but I'm sure it could be converted to work for other file types) so I'm not sure what transparency you would lose since jpeg's dont support transparency.
-
Sorry, I pasted the wrong link. Here is the correct one: http://bubble.ro/How_to_convert_an_image_to_grayscale_using_PHP.html I took that script and created a function that will do as you need. Just pass the function a path to the source image and the percentage in decimal form. I have also attached the image generated from the code below. <?php function convertImageToGrayscale($source_file, $percentage) { $outputImage = ImageCreateFromJpeg($source_file); $imgWidth = imagesx($outputImage); $imgHeight = imagesy($outputImage); $grayWidth = round($percentage * $imgWidth); $grayStartX = $imgWidth-$grayWidth; for ($xPos=$grayStartX; $xPos<$imgWidth; $xPos++) { for ($yPos=0; $yPos<$imgHeight; $yPos++) { // Get the rgb value for current pixel $rgb = ImageColorAt($outputImage, $xPos, $yPos); // extract each value for r, g, b $rr = ($rgb >> 16) & 0xFF; $gg = ($rgb >> & 0xFF; $bb = $rgb & 0xFF; // Get the gray Value from the RGB value $g = round(($rr + $gg + $bb) / 3); // Set the grayscale color identifier $val = imagecolorallocate($outputImage, $g, $g, $g); // Set the gray value for the pixel imagesetpixel ($outputImage, $xPos, $yPos, $val); } } return $outputImage; } $image = convertImageToGrayscale("otter.jpg", .25); header('Content-type: image/jpeg'); imagejpeg($image); ?> [attachment deleted by admin]
-
How are you planning to apply the percentage? If the percentage is 50% do you want the top half of the image to be grayscale or do you want the inner 1/2 to be grayscale? Here is a tutorial on converting an image from true color to grayscale using PHP. http://www.phpfreaks.com/forums/index.php/topic,302768.0.html It looks like it has to process each pixel, so altering that to only convert a percentage of the pixels should be straitforward.
-
Try putting this on your thank_you.php page for debugging purposes print_r($_POST); This will tell you if the POST values are actually there or not. If that doesn't work then the problem is on your form page. If it does work, then continue debugging your processing page. Insert echo's at crucial steps in the code to validate that variables have the values you expect them to have.
-
From the manual: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html (emphasis added)
-
No, not at all. But, the information you needed was in the manual. It was down in the comments section, but if you are spending hours researching a problem the best place to start is to fully read the manual for the particular function. Sorry if I offended you, but I believe in teaching people to fish rather than giving them a fish.
-
You are making this more difficult than it needs to be. The records should have a unique ID which doesn't have to have anything to do with the sort order. Records should be ordered by the timestamp the record was created (as thorpe suggests). You can then add an index number to be "displayed" to the user within the PHP code that creates the HTML (as miancu suggests).