Jump to content

spfoonnewb

Members
  • Posts

    276
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

spfoonnewb's Achievements

Member

Member (2/5)

1

Reputation

  1. Your MySQL $db object is not an instance of MySQLi for one thing. Try var_dump(write_mysql_log('Something Happened', $db)); to get the response.
  2. Here is another typical solution for this: SELECT users.username FROM users LEFT JOIN applied_jobs ON users.username = applied_jobs.candidate_name WHERE applied_jobs.candidate_name IS NULL
  3. As an expert, I do agree that in most situations (especially as a newbie to programming) you would want to normalize your data, however there are some cases where it may be better to do it another way. You can point out your opinion while #1 still answering the question and #2 not being so harsh about it. Best programming practices are just that, best practices, but that doesn't mean you should always follow the rule. Every project and application is different, and there are actually legitimate use cases for storing data in such a way. It's the same argument people have about storing serialized arrays or JSON in databases, and I used to think like you. The OP did post that he understands the risks associated with this decision. If he finds out later that he didn't use the best solution, let him learn then, but don't go off telling him you should "never" store data this way, that's simply not true.
  4. There are many ways to do this, however based on the above example, it would be the following: <?php $input = '1234567890024'; preg_match('/(\\d)(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{3})(\\d)/', $input, $match); if (isset($match[0])) { // If index 0 is set it will always match the entire RegExp. unset($match[0]); } $genderArr = array( 1 => 'Male', 2 => 'Female' ); if (isset($genderArr[$match[1]])) echo $genderArr[$match[1]]; var_dump($match);
  5. You can either build your own array to implode (use a key based recursive implode) or build the string yourself. Building the string yourself in this case is easiest assuming you needed that second listeners array rebuilt. Also, you should really validate that IP (make sure it's an IP in the correct format) and/or use prepared statements. <?php //Assume the dataSet appears like this based upon the provided foreach. $returnStats = array( 'listener' => array( (object) array( 'HOSTNAME' => '192.168.1.1', 'USERAGENT' => 'Google Chrome', 'CONNECTTIME' => '60', 'POINTER' => '0', 'UID' => '1Z5548488484' ), (object) array( 'HOSTNAME' => '192.168.1.2', 'USERAGENT' => 'Mozilla Firefox', 'CONNECTTIME' => '120', 'POINTER' => '0', 'UID' => '1Z5584844484' ) ) ); $listeners = array(); $ipStr = 'WHERE IN ('; foreach ($returnStats['listener'] as $listener) { $listeners[] = array( 'HOSTNAME' => (string) $listener->HOSTNAME, 'USERAGENT' => (string) $listener->USERAGENT, 'CONNECTTIME' => (string) $listener->CONNECTTIME, 'POINTER' => (string) $listener->POINTER, 'UID' => (string) $listener->UID ); $ipStr .= "'{$listener->HOSTNAME}',"; } $ipStr = substr($ipStr, 0, -1).')'; var_dump($ipStr); //You can use the listeners array if you need it, but you shouldn't define a key. var_dump($listeners);
  6. You can also use preg_replace('/\s/', '', $input) or explode() and many others. However, are you talking about an array or a string? because you mentioned an array but provided a string.
  7. Assuming the number is always the same length and format, you can use regex. Below is one example: <?php $input = '1234567890024'; preg_match('/([0-9]{1})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{3})([0-9]{1})/', $input, $match); if (isset($match[0]) && $match[0] == $input) unset($match[0]); print_r($match);
  8. Did you follow the first half of the tutorial? It seems as though you are likely missing the required library. The phpinfo() function generates a html page with all the information about the PHP installation, including the information about the Apache web server, the version and settings of the PHP compiler, and the supplemental PHP libraries that are installed and activated. We have to check the pdf libraries. The results should look something like this: PDF Support: enabled PDFlib Gmbh Version: 5.0.3 Revision: $Revision: 1.112.2.11 $
  9. Something like this should work. You would replace 1980 with your set variable. Something like $dob, etc. <!-- Birth Year --> <label for="birthYear">Year Born:</label> <select id="birthYear" name="birthYear"> <option value="">--</option> <?php // Display dates for Users between 18 and 100. for($i = $newestYear; $i >= $oldestYear; $i--) { if ($i == 1980) { echo '<option value="' . $i . '" selected="selected">' . $i . '</option>'; } else { echo '<option value="' . $i . '">' . $i . '</option>'; } } ?> </select>
  10. Here are two examples: <?php $minutes = 10; $time = strtotime('2012-09-10 09:00:00'); $time += 60 * $minutes; echo date('Y-m-d H:i:s', $time); ?> <?php echo date('Y-m-d H:i:s', strtotime('+10 minutes', strtotime('2012-09-10 09:00:00'))); ?>
  11. You can declare the variable static. There several other ways this can be done, however to answer your question in the simplest form, see below: class Main { public $classA, $classB; public static $shared; public function init(){ // Do some stuff return $this; } } class A { public function aMethod(){ $me = Main::$shared; // Same value as from B::bMethod() // Do some stuff return $this; } }
  12. Any text value you feed as the return will be considered true (there are special cases). You should explicitly define the value to be false, or return nothing at all. See: http://php.net/manual/en/language.types.boolean.php If you want the literal (string) value "TRUE," use quotes, otherwise it's boolean.
  13. This isn't really a PHP question. However, please see the following. I believe this is what you are trying to accomplish. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>PhpFreaks Test</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('a.sub').bind("click", function() { $.ajax({ url: 'temp.php', data: 'uid=' + $(this).attr('id'), success: function(response) { $('#test').html(response); } }); return false; }); }); </script> </head> <body> <h3>Test Script</h3> <p> <a href="#" id="1" class="sub">Sub 1</a> <a href="#" id="2" class="sub">Sub 2</a> <a href="#" id="3" class="sub">Sub 3</a> <a href="#" id="4" class="sub">Sub 4</a> <a href="#" id="5" class="sub">Sub 5</a> </p> <h3>Test Section</h3> <p id="test"> </p> </body> </html> <?php #Only because it's self, remove this statement for sub.php if (count($_GET) > 0) { ob_end_clean(); if (isset($_GET['uid'])) { echo $_GET['uid']; } else { echo 'Never use undefined variables. That\'s what that "Notice Error" is.'; } } ?>
  14. Something like this, for example. <?php $result = mysql_query(" SELECT `JobTitle`, `Company`, `Salary`, `Description`, `CompanyURL`, `PhoneNumber`, `Requirements`, `JobCategory`, `JobType`, `Apply_To`, `Email`, `State`, `Address`, `Country`, `Zipcode` FROM `Job-board` ") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo 'Job Title: <a href="http://www.destination.com/">'.$row['JobTitle'].'</a><br /><br />'; echo 'Company: '.$row['Company'].'<br /><br />'; echo 'Salary: '.$row['Company'].'<br />'; echo 'Description: '.$row['Company'].'<br /><br /><br />'; } ?>
×
×
  • 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.