Jump to content

Jervous

Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Jervous's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I would do: [code]<?php $string = "This is sample string and th--is is another"; $string_formatted = str_replace("--", "", $string); print_r(str_word_count($string_formatted)); ?>[/code] That's if I understood your question and needs properly.
  2. I am doing this right now, but I need to know a few things. What is the maximum length for the field and what type of field is it, (textarea, text, password, etc.)?
  3. What do you mean by yeah it would've? I have fixed the WHERE misspelling, and comment the code so you know what's going on. I have also changed the code a bit, because on a single profile page only one row would have to be returned. [code] <?php // Include connect file include("db_connect.php"); // Setup query and do query $query = "SELECT * FROM users WHERE id = '{$id}' LIMIT 1"; // Putting your variables in { and } makes them better somehow, it's slipped my mind ATM, but I know it's like a safety net. $result = mysql_query($query) or die(mysql_error()); // Count the number of rows returned $count = mysql_num_rows($result); // If the amount of rows returned is more than 0, continue. if ($count > 0){     // Put user info into array.     $user = mysql_fetch_assoc($result);     // Do stuff here.... } else {     // Show error message     echo "This user does not exist.";     // Template stuff, if any.         // Exit the script     exit(); } ?>[/code]
  4. For your original example, you wouldn't put mysql_num_rows() in the while() part because it doesn't return an array or anything like that, just a number. For the second example by desithugg, that wouldn't work if my table key was p_id or something like that. Here is what I would use: [code] <?php include("db_connect.php"); $query = "SELECT * FROM users WHRE id = '{$id}'"; $result = mysql_query($query) or die(mysql_error()); $count = mysql_num_rows($result); if ($count > 0){     while ($user = mysql_fetch_assoc($result)){         // Do stuff here....     } } else {     echo "This user does not exist.";     // Template stuff, if any.     exit(); } ?>[/code]
  5. To return the first 9 characters: [code] $test = "This is the string"; $output = substr($test, 0, 8); echo $output; // This is t ?> [/code] It doesn't return "he" because PHP counts whitespace as a character. EDIT: I accidentally pressed Preview so the reply never got sent. Also, you would use 0 and 8, not 9, because 0 - 8 is 9, 0 - 9 is 10.
  6. Hello, I am trying to parse an XML file for 3 of it's fields, but I have no idea how to. I know in PHP5 we have SimpleXML, but what can I use in PHP4? Below is an example of one of the items in the XML file. The fields in bold are the ones I need. [QUOTE] <item> [b]<title>Gemineye - Break Neck Radio (The Afro-Takeover)</title>[/b] − <link> http://podcast.digital-djs.com/imix/default.asp?id=11070 </link> − [b]<description> 01. (Intro) Spencer Doran - First of All 02. J. Dilla - Thunder 03. Blu - Soul Amazing (Soul Provider Remix) 04. Session - Freestyle 05. Jahi feat. Dwele - On My Own 06. Q-Tip feat. Andre 3000 - That's Sexy 07. (Break #1) Cyrus Tha Great - Island Music 08. Jay-Z - 99 Problems (DL's Firefly Remix) 09... </description>[/b] <pubDate>Mon, 31 Jul 2006 10:27:33 EDT</pubDate> <source url="http://feeds.feedburner.com/DDJiMix">Digital-DJs.com (Podcasts)</source> <bd:channelLink>http://www.digital-djs.com</bd:channelLink> <enclosure [b]url="http://broadcast.underground-fusion.com:8080/iMixes/Gemineye/Break%20Neck%20Radio%20(The%20Afro-Takeover).mp3"[/b] type="audio/mpeg"/> <media:content url="http://broadcast.underground-fusion.com:8080/iMixes/Gemineye/Break%20Neck%20Radio%20(The%20Afro-Takeover).mp3" type="audio/mpeg"/> </item> − <item> [/quote] Thanks, Michael Boutros
  7. It's because I am creating a script for users to upload and change their images, and yes, it is possible.
  8. Hello everyone. I am writing a script to resize images, and am stuck with this problem. I know for a fact that the problem is NOT that any of the variables are unset, because I have checked and they are all set. If anyone could help I would be very appreciative :) [code]// Make new image $new = imagecreatetruecolor($new_width, $new_height); // Create source image if ($file_type_ns == "jpg" OR $file_type_ns == "jpeg"){    $source = imagecreatefromjpeg("uploads/$file_name"); }     if ($file_type_ns == "gif"){    $source = imagecreatefromgif("uploads/$file_name"); }     if ($file_type_ns == "png"){    $source = imagecreatefrompng("uploads/$file_name"); } // Build new image imagecopyresampled($new, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output new image if ($info_type == "jpeg" OR $info_type == "jpg"){   imagejpeg($new, "images/$file_name_ns.jpeg", $quality); } if ($info_type == "gif"){   imagegif($new, "images/$file_name_ns.gif"); } if ($info_type == "png"){   imagepng($new, "images/$file_name_ns.png"); }[/code] $file_type_ns: the file type from $_FILES with the suffix extension $info_type: the new file type that a user has already chosen from a form Once again, all these variables have already been set. I get no errors or anything, but when I go to look at the new image, it is the right size and type, but it is completely black. Thanks to anyone who can help :)
×
×
  • 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.