-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
What are you asking? How to get the results from the query? Have a look at the mysql_fetch_assoc. NOTE: You should stop using the mysql_* functions as they are deprecated. Meaning they are no longer supported and could be removed from future versions of PHP. YOu should use mysqli or pdo instead.
- 1 reply
-
- 1
-
@rajasekaran1965 Welcome to PHPFreaks please read the rules regarding posting topics. Duplicate topics are not accepted. I have merged your two topics together. Also please wrap code you paste in to your post between tags or click the <> button in the editor.
-
You'd make a separate function which will determine which image functions to use depending on the image extension. Example (untest code). function getImageFunctionsByExtension($src) { $extension = pathinfo($src, PATHINFO_EXTENSION); switch($extension) { case 'gif': $functions = array('imagecreatefromgif', 'imagegif'); // list of gif function names break; case 'png': $functions = array('imagecreatefrompng', 'imagepng'); // list of png function names break; case 'jpg': case 'jpeg': $functions = array('imagecreatefromjpeg', 'imagejpeg'); // list of jpeg function names break; } return $functions; } Now replace $source_image = imagecreatefromjpeg($src); with list($imagecreatefromfunc, $imagefunc) = getImageFunctionsByExtension($src); $source_image = $imagecreatefromfunc($src); And then replace imagejpeg($virtual_image, $dest); with $imagefunc($virtual_image, $dest); The code will now use the correct image functions based on the extension of the image.
-
The tutorials you're have found most likely uses the GD image extension for creating the thumbnails. In that case all you need to do is swap out the jpeg functions to the gif or png equivalent Such as change imagecreatefromjpeg and imagejpeg functions to imagecreatefrompng and imagepng - for png images imagecreatefromgif and imagegif - for gif images
-
Use $json_object['google.com']['status']; instead $json_object is a multidimensional array not an object.
-
Could you tell us how you are testing the code? You should be running the code from http://localhost and the code should be saved in a file ending in a .php extension.
-
Yes. You can use a variable as the array key. Where is $piccurr defined?
-
$photo_category_list will not be defined on the first iteration of the while loop. This is why you are getting that notice. PHP is attempting to concatenate a value onto a variable which is not defined yet. To prevent the notice initialize the variable before the while loop $photo_category_list = ''; // initialize variable to empty string while($row = mysql_fetch_array($result)) { $photo_category_list .= <<<__HTML_END <option value="$row[0]">$row[1]</option>n __HTML_END; }
-
Guys I need Help some need to Combine Checkbox and Textbox Value
Ch0cu3r replied to sohailsaif's topic in PHP Coding Help
It would be helpful if you could at least explain what it is you are trying to do. You have so far posted a vague question and posted a picture which does not explain anything. Having the word URGENT in your title does not get your question answered anytime sooner. All members here have given up their own free time to help out. NB: I have cleaned this thread up -
Guys I need Help some need to Combine Checkbox and Textbox Value
Ch0cu3r replied to sohailsaif's topic in PHP Coding Help
Yes. That is how forms work. What has the picture got do with your question? -
Subtract times in database from current time.
Ch0cu3r replied to mikeinaustin's topic in PHP Coding Help
What you trying to do? Calculate the difference between two dates? Have a look at dateTime::diff NOTE: Please wrap code within tags when posting code. For now I have edited your post for you. -
Did you miss reply #10? Also why are you posting code which a) you did not write and b) has no relevance to your problem.
-
A for loop can also count backwards too. To so you'd use the opposite operators for each expression. The < operator means less than. The opposite operator would be the > (greater than) operator $i++ means increment $i by one. The opposite operator would be $i-- which means deincrement $i by one.
-
That is a good start. For the others you will need to write separate for loops for outputting the remaining patterns. Afterwards consider re-factoring your code into reusable functions You can pad the string with whatever characters you want. You don't have to pad your lines with . Your could instead apply white-space: pre CSS styling to the HTML element your patterns are contained in. Who mentioned arrays? I see no need for arrays in this exercise. A for loop is all that is required. You may find the following functions helpful str_repeat and str_pad as well.
-
Here is a starting point http://php.net/for. Learn how to use a for loop and have a go at it yourself. Get stuck and we will try to help you. We WILL not provide code for you. Copy and pasting code will not teach you how to program. Understanding the problem and actually writing code is what helps you to learn to program. What you are attempting to do is something that anyone can achieve if you have learned the very basics of PHP. The PHP documentation is a great resource for you if you are new to the language.
-
Checking If the MySQL Database Connection is Working?
Ch0cu3r replied to glassfish's topic in PHP Coding Help
Why not look at the relevant documentation? It explains what each connection method returns and code examples of how to connect and test if the connection works. mysql mysqli pdo -
The error you are getting is not a PHP error but an XML error, most likely due to the XML being generated is invalid.
-
If you want to use Microsoft Live Writer you are going to need write and compile a custom .NET plugin.
-
When you do that the corresponding superglobal variable will be an array containing the fields values. So you will need to loop over the array to get each value for each field. Example starting code if(is_array($_FILE['image'])) { // loop over each uploaded image foreach($_FILE['image'] as $image) { // add your code here for handling file upload, example starting code if (!is_valid_type($image['name'])) { // not a valid file, issue an error } if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { // add the image to database } else { // problem with moving file } } } Note as you are uploading multiple images you will need to reconsider your database structure. It is a bad database design if added all the images into the same row. You will be better of inserting the uploaded images for the product into a separate table. The relationship between these table will be one to many (as a product can have multiple images). You'd use the products id as the foreign key in the images table. When fetching the data for product from the table you'd use a JOIN to retrieve the images that correspond to the image. If what I said above makes no sense. Read this article to get a better understanding.
-
Parse error: syntax error, unexpected end of file
Ch0cu3r replied to Paul_Withers's topic in PHP Coding Help
You need to go through your code and make sure each statement has matching opening and closing braces. If you had formatted your code it'll be alot easier to identify where the closing brace should go. Ideally every time you open a brace you should indent the code by one when you type a closing brace you remove a tab example if( conditon ) { statemet1; statement2; while( something ) { doThis; andThat; } } Notice the opening and closing braces all line up, each statement is neatly indented. This is how you should format your code. Also if you are going to use large chunks of HTML in your code consider moving it to another file and use include/require when you need it. You should try to keep your HTML and PHP code separate as much as possible. -
Let certain usernames and Messages appear in its own color
Ch0cu3r replied to cobusbo's topic in PHP Coding Help
The code for in_array is fine the problem is with your code. $admin is only defined on line 186 if the condition on line 136 is true if (isset($StringyChat_name) && isset($StringyChat_message)) You need to modify your code so $admin is not defined within a condition. -
Let certain usernames and Messages appear in its own color
Ch0cu3r replied to cobusbo's topic in PHP Coding Help
Why? The code you posted in reply #3 is on the right track. The problem is you are giving in_array the wrong values. You should pass $name as the first argument and $admin as the second argument. if (in_array($name, $admin)) { print '<span style="color:red">' . $name . '</span>'; } else { print $name; } A better way would be to add another column in your users table in the database. The value stored in this column will determine the role the user has. Example normal users have the role set to 1, 2 is for moderators and 3 is for admins. Then all you need to do is check the role to determine the color of the users name. Example code // an array storing the colors for each role. The role is used as the key $colors = array( 1 => 'black', 2 => 'blue', 3 => 'red' ); $name = 'johnDoe'; $role = 3; // dynamically assigns the color based on role echo '<span style="color: ' . $colors[$role] . '">' . $name . '</span>'; // will show as red -
These two lines need to be inside your while loop $cardname = $row['Name']; $url = "http://mtgimage.com/card/$cardname.jpg"; Variables need to be defined before you can use them.
-
Let certain usernames and Messages appear in its own color
Ch0cu3r replied to cobusbo's topic in PHP Coding Help
The error message tells you what you did wrong. If you have read the documentation for in_array you would understand what values it expects.