Jump to content

johnmerlino

Members
  • Posts

    71
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

johnmerlino's Achievements

Member

Member (2/5)

0

Reputation

  1. thanks for response, display_error was set to Off, so I turned it on.
  2. Hey all, In this basic example: $db = new mysqli('localhost','root','pass','schools'); $query = "select * from schools where ".$type." like '%" . $term . "%'"; $result = $db->query($query); Let's say the $query local variable holds a string constructed of a mysql query that gets passed as argument to query method of mysqli instance. What exactly is the return value of query()? What is the type that is stored in the variable $result? I heard it called a "result object". Is a result object just a pointer to a mysql resource or something? Here: $num_results = $result->num_rows; for($i=0; $i < $num_results; $i++){ $row = $result->fetch_assoc(); } $result->fetch_assoc(); returns a record resource as an array $row = $result->fetch_object(); returns a record resource as an object; which is preferred? Can I work with array functions on the latter? thanks for response
  3. Yeah this was silly error. I didnt realize I was using $_POST rather than $_FILE.
  4. thanks for response, now that I copied the file into the new php.ini. Suddenly php stops raising exception errors and rather I just get a "server error" from the browser. Was some configuration setting reset?
  5. Hey all, I have a situation where there's multiple forms on a single page and when the user clicks the button, I don't want them to be navigated away from page but rather the transaction occurs on same page. Hence, everything occurs in a file called file_generator.php. I have these two forms: <form action="" method="post" enctype="multipart/form-data"> <tr> <td>Upload the data</td> <td><input type="file" name="file" /> </td> </tr> <tr> <td><input type="submit" name="upload" value="Generate List" /></td> </tr> </form> <form action="" method="post"> <tr> <td>Add Content:</td> <td><textarea rows="2" cols="20"></textarea></td> </tr> <tr> <td>Get the output:</td> <td><input type="submit" name="download" value="Get List" /></td> </tr> </form> Then when the form gets submitted it checks which form was submitted: foreach($_POST as $name => $value){ switch($name){ case 'upload': upload_data(); break; case 'download': download_data(); break; } } So if the user wants to upload a file, this function gets called: function upload_data(){ $file = $_POST['file']; if(isset($file)){ if(file_is_valid($file)){ echo "true"; } } else { echo "No file chosen"; } } For some reason, it triggers the else above, even though I selected a file, and that $file variable therefore should be set. Thanks for response
  6. Thanks for response, but from the unix shell, I did the following: cd ~ cd /etc/ ls php.ini.default hp.ini.default-5.2-previous So there was no php.ini per se. Hence, I did the following: mate php.ini.default sudo touch php.ini (copied content from php.ini.default into php.ini and then saved file) When I listed the /etc contents, the php.ini was now in there: php.ini php.ini.default php.ini.default-5.2-previous Yet, under Loaded Configuration File, it still says none. Platform is Mac OSX Thanks for response
  7. Hey all, this function returns 0, rather than a string consisting of html tags: function cost_per_distance_table($distance,$divisor){ $str = ""; $str += "<table>"; $str += "<tr>"; $str += "<td>Distance</td>"; $str += "<td>Cost</td>"; $str += "</tr>"; while($distance <= 250){ $str += "<tr>"; $str += "<td>" . (string)$distance . "</td>\n"; $str += "<td>" . (string)($distance/$divisor) . "</td>\n"; $str += "</tr>"; $distance += 50; } $str += "</table>"; return $str; } echo cost_per_distance_table(50,10); Not sure why. Thanks for response.
  8. In terms of configuration it says this: Configuration File (php.ini) Path /etc Loaded Configuration File (none) It says none for loaded configuration file. If this is issue, how do I correct it? Thanks for response
  9. Hey all, So I was have common problem with date() function in php5.3. Someone said the error message suggests that your php.ini settings have 'EDT/-4.0/DST' set as your timezone setting and should rather be 'America/New_York' instead. Now i have two php.ini files: php.ini.default php.ini.default-5.2-previous. running phpinfo() just tells me that the php.ini is located in etc but doesn't mention which php.ini is in use. So to figure out which one, I run this: $inipath = php_ini_loaded_file(); if ($inipath) { echo 'Loaded php.ini: ' . $inipath; } else { echo 'A php.ini file is not loaded'; } And this outputs the else statement "not loaded". How could the php.ini not be loaded? thanks for response
  10. Hey all, I deselect a checkbox. Then click update. Yet the only thing that gets passed in the post array are the items that are already checked previously. How can I pass the item that was unchecked into the array? Thanks for response
  11. Hey all, the foreach loop allows you to iterate through an array and pass an index: foreach($array as $key=>$value) { // $value is the current item in array and $key is index } I want to do the same thing but add the functionality as part of my Enumerator class: class Enumerator { public $arr; public function __construct($array=array()) { $this->arr = $array; } public function each($lambda) { array_walk($this->arr, $lambda); } } So for example now I can do this: $elements = new Enumerator(array('email','fax','phone','postal mail')); $elements->each(function($l){ echo form_checkbox("checked[]",$l); }); But I may want to do this: $elements = new Enumerator(array('email','fax','phone','postal mail')); $elements->each_with_index(function($l,$i){ if($i % 2 == 0){ echo form_checkbox("checked[]",$l); echo "</br>; } else{ echo form_checkbox("checked[]",$l); } }); thanks for response
  12. can I use a regular expression with str_replace if, for example, I want to replace a number of different characters like "_" "-"?
×
×
  • 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.