Jump to content

nankoweap

Members
  • Posts

    113
  • Joined

  • Last visited

Everything posted by nankoweap

  1. if you want that kind of control over an ID column, i'd suggest not using auto increment and write the code to do it yourself. of course, i'm not sure why one would want to do this. i mean, what value-add to the application and its users would justify this? i make my ID columns unsigned bigints and don't worry about it. jason
  2. have you tried something like? ... $item = array(); while ($row = mysqli_fetch_array($result)) { $item[$row['name']] = $row['price']; } ... jason
  3. yep. that's the primary issue i have with this implementation and why it's likely to change. there are a number of use-cases where multiple biz objects will be utilized - each having its own connection. not too kind - resource wise. preciate the feedback. jason
  4. i'm not so sure about a connection being required of every class. i reckon it depends upon your application's architecture/design. in my web applications a subset of business classes provide model-services (classes that interact directly with the database and both abstract from and provide the view with a clean, simple interface to interact with the database) all extend a base business class whose constructor obtains a connection and whose destructor closes the connection. here's that base class: <?php include_once('classes/AppInfo.php'); class BaseBo { protected $appInfo; protected $dbc; function __construct() { $this->appInfo = AppInfo::getInstance(); $this->dbc = mysqli_connect( $this->appInfo->getMysqlHost(),$this->appInfo->getMysqlUser(), $this->appInfo->getMysqlPassword(),$this->appInfo->getMysqlDatabase()) or die('Error connecting to database.'); } function __desctruct() { mysqli_close($this->dbc); } } ?> and here's a snippet of a business class that extends BaseBo... <?php include_once('classes/bo/BaseBo.php'); include_once('classes/bean/Bike.php'); include_once('classes/bean/User.php'); class BikeManager extends BaseBo { public function getBike(User $user, $bikeId) { if (is_null($user) || $bikeId <= 0) return; $userId = $user->getId(); $b = new Bike(); $b->setId($bikeId); $sql = "select a.b_id, a.m_id, a.model, a.b_year, b.description " . "from bike a, make b " . "where a.u_id = $userId " . "and a.b_id = $bikeId"; $result = mysqli_query($this->dbc, $sql); $row = mysqli_fetch_array($result); mysqli_free_result($result); if ( ! is_null($row)) { $b->getMake()->setId($row['m_id']); $b->getMake()->setDescription($row['description']); $b->setYear($row['b_year']); $b->setModel($row['model']); } return $b; } // getBike } // BikeManager ?> in this simple example, if a view component (i.e. a web page) requires bike information, the php snippet within it will create a new BikeManager and ask it for a particular bike's information. there are some issues with this approach, but i'm a php noob and still learning about the internals of how the php engine, mysqli, etc actually work. i may change this approach to achieve better performance, resource management... having all this code localized to a specific application layer, though, lends itself well to change without polluting the other application layers. jason
  5. integration with paypal is rather simple. for more information, check out: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_overview jason
  6. your statement is failing. consider changing: DATE_FORMAT(entrydate, '%M %d, %Y') AS date to DATE_FORMAT(entrydate, '%M %d, %Y') AS entrydate jason
  7. consider performing the update first, then... http://us3.php.net/manual/en/function.mysql-affected-rows.php if the number of rows affected is zero, insert. jason
  8. there may be an easier way, but there's.... http://us.php.net/manual/en/function.strtok.php jason
  9. easiest way is to let mysql do it by using the date_add function. should be something like: select date_add(datetime_column, interval 3 hour) from some_table ... and if you store each user's gmt offset or calculate the user's gmt offset, you could easily tailor the query. first convert it to gmt and then adjust according to the user's profile. jason
  10. in one of the webapps i'm converting to php i use a wizard-like UI for report generation. single page. the user can move forward and back, etc. since the data isn't secure in nature and it's composed of only a few elements, i chose to maintain state in the form itself using hidden elements. the first thing you want to do is determine the current step. if the user hit the cancel button, go to the home page. collect the current state from the form elements. if the user hit the back button, go to the previous step. if the user hit the next button, go to the next step. if the user hit the finish button, display the results. amongst the html i have a bit of php to determine the current step and the form elements to display and hide. jason
  11. nah. winderz is a different beast. new lines are a combination of carriage return and newline whereas unix-based systems are typically newline only. there's probably a php function for this, but i'm a php noob and don't know. change "\n" to "\r\n" to the code and see what happens. jason
  12. nl2br would work. another option would be to enclose the text in a <pre></pre> tag. i do this when displaying messages the user typed in and it preserves not only line breaks, but spaces as well as faux html tags the user may have type in like <snip> and such.
×
×
  • 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.