ShawnCplus 456 Code Monkey Team Colleague
function count_dir($dirname)
{
  return count(array_slice(scandir($dir), 2));
}

$seasons = array('spring', 'summer', 'winter', 'fall');
$springcount = $summercount = $fallcount = $wintercount = 0;
foreach ($seasons as $season) {
  $seasoncnt = $season . 'count';
  $$seasoncnt = count_dir("images/" . $season);
}
// done

Whoops: For Reference Variable Variables, http://php.net/scandir, http://php.net/array_slice

ShawnCplus 456 Code Monkey Team Colleague

thanks ShawnCplus.. so do u advice all newbies to use $_GET instead of $_REQUEST... and use it in the same way as $_REQUEST.

Well, not only get but use $_GET, $_POST, and $_COOKIE separately. Also, never mix REQUEST and the others. Even though REQUEST contains the data it is treated as a separate variable so modifying GET/POST/COOKIE doesn't change REQUEST. Also, it should be noted that using REQUEST can possibly introduce some very hard-to-debug bugs since if you have a GET variable named SomeVar and a POST variable named SomeVar they will override each other (the one winning being determined by the request_order PHP ini setting)

ShawnCplus 456 Code Monkey Team Colleague

$_REQUEST: is sort of a combination of the two, any vars in either $_GET or $_POST will appear in $_REQUEST. However, most experienced programmers will warn you against using this for various reasons, rather just stick to $_GET and $_POST.

$_REQUEST Also includes $_COOKIE .

ShawnCplus 456 Code Monkey Team Colleague
int flipLocation(int numberUsed)
{
	cout << "Enter flip location ";	
	cin >> flipLocation;
	if (flipLocation > numberUsed)
		cout << "Invalid flip location";
		cout << "Enter a new flip location ";
		cin >> flipLocation;

	return flipLocation;
}

I see lines 6 through 8 are indented. I assume that means they are part of the if statement on line 5. However, they are not inside brackets, so lines 7 and 8 execute regardless. Do you want that? What if the user enters a bad flipLocation TWICE? They won't have a chance to correct their second bad answer. My suggestion would be to put lines 6 through 8 inside brackets and change the if-statment on line 5 to a while statement so the user can screw up many times and still have a chance to correct.

Might want to clarify a do/while otherwise nothing will happen :)

ShawnCplus 456 Code Monkey Team Colleague

Firstly, for both scripts do

$ticket_number = intval($_POST['Ticket_Number']);

And use that instead of $_POST just in case someone enters in something that isn't a number.

Secondly use a SELECT statement to see if a ticket with that number exists and if it does execute the DELETE like so:

$query = 'DELETE FROM Tickets WHERE Ticket_Number = ' . $ticket_number;
ShawnCplus 456 Code Monkey Team Colleague

I already gave you an example for that: OPTIONALLY ENCLOSED BY "\"" LINES TERMINATED BY "\n" I would point you to the documentation but evidently there is a major power outage in Sweden right now and MySQL's servers are down (not joking)

ShawnCplus 456 Code Monkey Team Colleague

Well you said Javascript works fine for looking through the tables so instead of trying to make the CSV with Javascript just set a form field to the data you've gathered ie.,

<form action="create_csv.php" id="create_csv"><input type="hidden" name="csv_data" id="csv_data"/></form>
<script type="text/javascript">
// whatever magic you're doing to gather the data
document.getElementById('data_csv').value = yourawesomedata;
document.getElementById('create_csv').submit(); // submit yourawesome data to the PHP script create_csv.php
</script>
ShawnCplus 456 Code Monkey Team Colleague

You're using a relative path "csv/unconvert_tester.csv" so MySQL seems to be placing it in a default location for outfiles. Just specify an absolute path (starting with /) to tell it the exact location.

ShawnCplus 456 Code Monkey Team Colleague

You could have Javascript just create an array of data, JSON encode the array, set that to a form value and submit the form to a PHP page which itself creates the CSV instead of having PHP or Javascript do it all

ShawnCplus 456 Code Monkey Team Colleague

OPTIONALLY ENCLOSED BY '"' get rid of that completely unnecessary mysql_real_escape_string('"') BS

ShawnCplus 456 Code Monkey Team Colleague
$result = mysql_query($sql);
if (!$result) {
  die(mysql_error());
}

That'll tell you if the query is actually executing or not. And you don't have to surround variables with "" if that's the only thing in the statement. mysql_query($sql); or 'some string' . $variable are both fine and the preferred way to do it.

ShawnCplus 456 Code Monkey Team Colleague

Why are you using mysql_real_escape string for your quote but not for $table which is coming directly from POST?. Also what do you mean the file doesn't work, is the csv file empty or what?

ShawnCplus 456 Code Monkey Team Colleague

you're already in PHP, you don't need to do <?php echo Also, you're in double quotes so you must surround the $onrow["index"] with {} ie., {$onrow["index"]}

tulipputih commented: thanks for your explanation :).it helps me understanding php better +1
ShawnCplus 456 Code Monkey Team Colleague

OK, then post your code and I can give you a hand otherwise I'm just guessing at what it looks like.

ShawnCplus 456 Code Monkey Team Colleague

I have the same problem and I check all the things and precautions. My code is ok. But I dont know what is the problem. My battery is gone down and I just want to post it to get answers when I came again. So please help I also debug it, and that's ok. Help it mess up my time.

Thanks

Read the FAQ dealing with this problem instead of reviving 2 year old threads.

ShawnCplus 456 Code Monkey Team Colleague

Cool, how's that working out for you?
http://www.daniweb.com/forums/announcement8-2.html

iamthwee commented: For quoting a line from 'Fight club' +22
ShawnCplus 456 Code Monkey Team Colleague

With a foreach, $key is the key of the array and obviously, $value is the value so for

$array = array('key1' => 'value1', 'key2' => 'value2');

foreach will act like this

foreach ($array as $key => $value) {
  echo $key . '=' . $value; // key1 = value1, etc.
}

http://php.net/foreach

ShawnCplus 456 Code Monkey Team Colleague

does anyone know how to get the max lenght of any line in the file? the fgetcsv() requires a lenght argument that should ne greater that the longest line in the file.

Unless you're using PHP4 you don't need it, if the PHP document shows an argument in [] then it is optional

ShawnCplus 456 Code Monkey Team Colleague

http://php.net/fgetcsv There's a builtin PHP function

ShawnCplus 456 Code Monkey Team Colleague

Evidently you missed the entire page about foreach then.

ShawnCplus 456 Code Monkey Team Colleague

php.net/arrays and php.net/foreach. Go read those.

ShawnCplus 456 Code Monkey Team Colleague

heh, I said mysql_query, etc. You're still using mysqli

ShawnCplus 456 Code Monkey Team Colleague

K, then try the script using plain mysql_query functions. If that works then it's something wrong with mysqli.

ShawnCplus 456 Code Monkey Team Colleague

Stupid question, is MySQL actually running?

ShawnCplus 456 Code Monkey Team Colleague

Take that damn @ out from in front of the first line. @ suppresses errors so you can't see them.

ShawnCplus 456 Code Monkey Team Colleague

Use PDO/mysqli and prepared statements, that's the easiest way to prevent it. Forget about all the magic_quotes BS. mysql::prepare

ShawnCplus 456 Code Monkey Team Colleague

The AJAX response just has to send like a JSON response then you parse the response and set them in your success callback.

ShawnCplus 456 Code Monkey Team Colleague

like I said, for primitives you can use the is_<type> methods (is_int, is_string, is_bool, etc). Keep in mind that if you're using this for OOP and you have a child class with a method of the same name taking a different number of arguments the function or your design is probably wrong. Also be sure that you're not confusing function overloading and polymorphism. They aren't the same thing. Polymorphism is implicit in PHP due to being loosely typed.

class Shape
{
  protected $name;
  public function setName($name) { $this->name = $name; }
  public function getName() { return $this->name; }
}

Class Circle extends Shape {}

function getshapename(Shape $someshape)
{
 // yeah, dumb function, just an example
  return $someshape->getName();
}

$shape = new Shape();
$shape->setName('hello');
$circle = new Circle();
$circle->setName('world');
echo getshapename($shape); // hello
echo getshapename($circle); // world (Circle is a Shape [see liskov substitution principle])
ShawnCplus 456 Code Monkey Team Colleague

You are correct, method overloading is and will never be in the language. However, there are ways to get around this. The func_get_args function can be used to retrieve an array of all arguments passed to the function. Also, as you mentioned, PHP is loosely typed but can be "Type Hinted."

One way to go about faking method/function overloading is to use is_<type> functions on the passed arguments to swap them around. ie.,

function swapParams($someint, $somestring)
{
  if (is_int($somestring) && is_string($someint)) {
   $tmp = $someint;
   $someint = $somestring;
   $somestring = $tmp;
  }
  // do stuff here
}

Also correct is that there is no operator overloading. Once again though it can be faked. The Magic Methods can be used to a very limited extent to overload the equivalent [] , -> and :: operators.

ShawnCplus 456 Code Monkey Team Colleague

Searching what, a database or text?

ShawnCplus 456 Code Monkey Team Colleague

It's not PHP, it's CSS. It's just a background-image applied to the textarea

ShawnCplus 456 Code Monkey Team Colleague

You might want to read your book or the tutorial or whatever you're using to learn PHP again because there are WAY too many things wrong with that script.

ShawnCplus 456 Code Monkey Team Colleague

You might want to show us some code, and use code tags when you do

ShawnCplus 456 Code Monkey Team Colleague

return subConfirm() not just subConfirm()

ShawnCplus 456 Code Monkey Team Colleague

Did you look at the system event log? What did it say?

ShawnCplus 456 Code Monkey Team Colleague
ShawnCplus 456 Code Monkey Team Colleague

A) Use code tags
B) It's always going to echo 1
C) You're not retrieving data from the request (in this case $_POST D) Go read the PHP manual http://php.net and w3schools.com

ShawnCplus 456 Code Monkey Team Colleague

Lightbox, thickbox, tightbox, use Google and take your pick.

ShawnCplus 456 Code Monkey Team Colleague

You probably would never make much if any money creating a forum with PHPBB and its ilk out there.

ShawnCplus 456 Code Monkey Team Colleague

I'm pretty sure we said don't post minified versions. Ya gotta have some newlines and indentation in there.

ShawnCplus 456 Code Monkey Team Colleague

It should also be noted that you can't do this outside of the ComplexNum class

result.real = cNum1.real - cNum2.real;
result.img = cNum1.img - cNum2.img;

You declared real and img to be private members. You can't access them without some sort of accessor method ie., getReal, getImg. So define those functions or make the members public

ShawnCplus 456 Code Monkey Team Colleague

What's the point of using cNum1 and cNum2, you already have the variables first and second to use.
You can do the same thing for both functions

ComplexNum ComplexCalc::subComplex( ComplexNum &first, ComplexNum &second )
{
	ComplexNum* result = new ComplexNum();
	result->setValues(first.real - second.real, first.img - second.img);
	return *result;
}

But if you want to keep your code as-is just include the header for ComplexNum in the ComplexCalc.h because right now it doesn't know what ComplexNum is so it's an "incomplete type"

ShawnCplus 456 Code Monkey Team Colleague

When an index is created it takes up space on the filesystem. So as long as you're fine with taken up more space to get more speed indices are the way to go.

ShawnCplus 456 Code Monkey Team Colleague
// if you're using XHTML
str_replace('<br />', "\n", $string);
// if you're using HTML
str_replace('<br>', "\n", $string);
ShawnCplus 456 Code Monkey Team Colleague

Read the FAQ

ShawnCplus 456 Code Monkey Team Colleague

Make sure you have indices on the column you're searching, that's probably the easiest way to speed things up but it's a size vs. speed trade-off.

ShawnCplus 456 Code Monkey Team Colleague

Well firstly, how 'bout you give us a non-minified version of the javascript. I am not about to go wading through that block of crap. And by non-minifid I mean put some damn newlines in there, perhaps some tabs or spaces, some form of indentation. If it was written this way then whoever wrote it needs to be shot.

ShawnCplus 456 Code Monkey Team Colleague

The tilde has no special meaning, it was just chosen as the delimiter so the slashes didn't have to be escaped. You can choose pretty much any delimiter.

$regex1 = '/http:\/\/www\.example.com\/blah/';
// vs
$regex2 = "#http://www\.example\.com/blah#';

I prefer to use / and # but it looks like the tilde was their choice.

ShawnCplus 456 Code Monkey Team Colleague

Well if you're trying to extract the username you can just do this.

$url = 'http://www.myspace.com/username';
$urlparts = explode('/', $url);
$username = end($urlparts);
ShawnCplus 456 Code Monkey Team Colleague

You forgot the ending }