php-general Digest 16 May 2009 13:15:18 -0000 Issue 6124

Topics (messages 292666 through 292678):

Re: CSS & tables
        292666 by: Michael A. Peters
        292667 by: Michael A. Peters
        292669 by: Paul M Foster
        292670 by: Paul M Foster
        292673 by: Ashley Sheridan
        292674 by: Bas Avezaat
        292678 by: Robert Cummings

Re: Sorting times (SOLVED)
        292668 by: German Geek

Re: read the last line in a file?
        292671 by: Per Jessen

Re: Software to read/write Excel to CD?
        292672 by: Ashley Sheridan

Shopping Cart
        292675 by: Vernon St Croix
        292676 by: Ashley Sheridan
        292677 by: Darrel St Croix

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
tedd wrote:
At 2:06 PM -0400 5/15/09, Tom Worster wrote:
for one thing, a table is a great way of representing relations
(http://mathworld.wolfram.com/Relation.html). data tables are the canonical example but very often a form's structure is a relation, e.g. between labels
and input fields, or between multiple input fields.

some of the best designed and behaving web sites i know use tables in ways
that a list apart would consider heathen.

Heresy!  :-)

However, there are occasions such as in a calendar where not using a table would be more than difficult.

Calendars are tabular data and thus a table is right way to do it.

--- End Message ---
--- Begin Message ---
Nathan Rixham wrote:
tedd wrote:
At 2:06 PM -0400 5/15/09, Tom Worster wrote:
for one thing, a table is a great way of representing relations
(http://mathworld.wolfram.com/Relation.html). data tables are the canonical example but very often a form's structure is a relation, e.g. between labels
and input fields, or between multiple input fields.

some of the best designed and behaving web sites i know use tables in ways
that a list apart would consider heathen.

Heresy!  :-)

However, there are occasions such as in a calendar where not using a table would be more than difficult. I haven't received a decree yet as to IF that would be considered column data or not.

I'm gonna differ on this one, when you simply float each calender item to the left you're pretty much done, in many cases i find it easier than tables.

But with tables, you can use th and td elements to describe the tabular data, and non visual browsers will know what to do with those tags to better describe the data in the table.

Also, by using a table, you don't end up with funny display should the calendar be displayed in a small browser window. Yes, you'll end up with the dreaded horizontal scroll bar in a small window, but in the case of tabular data, that's what should happen. The only way to accomplish a div/css solution is with absolute position.

Positioning tabular data with divs also goes completely to hell if the user turns of css. Tables still render the tabular data correctly with CSS turned off.

That's why tabular data should be done with the table tag.

Tables aren't themselves evil, using them for layout it.

Example of the proper use of tables:

http://www.shastaherps.org/SearchRecords?horder=3&page=1

The layout (and I confess, I'm no artistic design guru) is fairly basic div/css based layout. Haven't even tested in IE or Safari (fricken MS and Apple won't port their browsers to Linux) - there may be some CSS issues.

The tabular data however (search results) is done the way tabular data should be done - via table. I could have done it with divs but table was the proper tag.

All the "tables are evil" tripe needs to be noted that the tripe is within the scope of layout design, not the scope of tabular data.


--- End Message ---
--- Begin Message ---
On Fri, May 15, 2009 at 03:12:06PM -0400, HallMarc Websites wrote:

> Um... sorry to jump in as a late arrival yet there you go....
> 
> What limitations? You could provide a layered layout using CSS and png
> graphic format. As for setting up columns check out float and clear and
> you're all set. TABLE, TR, TD, TBODY, etc were never intended to be used in
> the manner we see today. If you are blind and you hit a site with a mess of
> nested tables then.. well you might leave because of the garbage you have to
> listen to when the page loads. Speaking of which, correct me if I am wrong
> and my info is out of date but TABLEs are loaded one at a time by browsers
> and cause longer load times than necessary.

Tables do take longer to load. The browser has to do a lot of math to
determine how wide to make cells, etc. I don't know how this compares
with CSS divs and such, speed wise.

> 
> All in CSS is the way to go. CSS3 will make our lives easier and will
> contain so many new features that it will be released in batches (modules)

No doubt. But if history is any guide, it will be quite some time before
browsers support a new standard. In fact, browsers typically fail to
support existing standards fully.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Fri, May 15, 2009 at 01:25:42PM -0400, PJ wrote:

> I know of no better place to ask. This may not be strictly a PHP issue,
> but...
> I am busting my hump trying to format rather large input pages with CSS
> and trying to avoid tables; but it looks to me like I am wasting my time
> as positioning with CSS seems an impossibly tortuous exercise. I've
> managed to do some pages with CSS, but I feel like I am shooting myself
> in the foot or somewhere...
> Perhaps I am too demanding. I know that with tables, the formatting is
> ridiculously fast.
> Any thoughts, observations or recommendations?

I think it's pretty telling that on a list of professionals who create
websites constantly, the overwhelming concensus is that for forms,
tables are the preferred solution.

I liken this sort of discussion to the dichotomy between movie critics
and people who actually go and see movies. The critics inevitably have
all sorts of snobby things to say about the movies which are best
attended. I'm not sure why anyone listens to any critic on any subject.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Sat, 2009-05-16 at 02:25 -0400, Paul M Foster wrote:
> On Fri, May 15, 2009 at 01:25:42PM -0400, PJ wrote:
> 
> > I know of no better place to ask. This may not be strictly a PHP issue,
> > but...
> > I am busting my hump trying to format rather large input pages with CSS
> > and trying to avoid tables; but it looks to me like I am wasting my time
> > as positioning with CSS seems an impossibly tortuous exercise. I've
> > managed to do some pages with CSS, but I feel like I am shooting myself
> > in the foot or somewhere...
> > Perhaps I am too demanding. I know that with tables, the formatting is
> > ridiculously fast.
> > Any thoughts, observations or recommendations?
> 
> I think it's pretty telling that on a list of professionals who create
> websites constantly, the overwhelming concensus is that for forms,
> tables are the preferred solution.
> 
> I liken this sort of discussion to the dichotomy between movie critics
> and people who actually go and see movies. The critics inevitably have
> all sorts of snobby things to say about the movies which are best
> attended. I'm not sure why anyone listens to any critic on any subject.
> 
> Paul
> 
> -- 
> Paul M. Foster
> 
I think the argument of tables vs css can go a little deeper too. These
days, sites should not only be developed with good clean code that
validates, but semantic markup. If your client doesn't like/know what
this is, just give it to them in terms of seo!

Tabular data should be kept in tables, layout shouldn't be done with
tables if you can avoid it, but if you must use them, at least check the
site after in a text browser or screen reader to get an impression of
how others 'see' it. Same goes for other aspects of a site too. So many
times I've seen people (DreamWeaver users for the most part) litter an
entire page with <span> tags, most of which do nothing more than bolden
or italicise text, which is not all that semantic. Codes lists are
another one too. That code should be in a list, as it makes more sense
semantically.

Trust me, semantics are gonna be the next big thing, especially if
browsers start to delve into what M$ has dubbed 'slices' in IE8. Sites
are forever sharing content and scraping small content areas from other
sites, so wouldn't it be good to make it easier in some respects and
give a bit more context and meaning to content?


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
Paul M Foster wrote:
On Fri, May 15, 2009 at 01:25:42PM -0400, PJ wrote
I've been using div's with in css float and only setting width of elements, that way your div grow dynamically pending on data size. it takes some time figuring it out but you should be able to find examples on the net.

Bas
I know of no better place to ask. This may not be strictly a PHP issue,
but...
I am busting my hump trying to format rather large input pages with CSS
and trying to avoid tables; but it looks to me like I am wasting my time
as positioning with CSS seems an impossibly tortuous exercise. I've
managed to do some pages with CSS, but I feel like I am shooting myself
in the foot or somewhere...
Perhaps I am too demanding. I know that with tables, the formatting is
ridiculously fast.
Any thoughts, observations or recommendations?

I think it's pretty telling that on a list of professionals who create
websites constantly, the overwhelming concensus is that for forms,
tables are the preferred solution.

I liken this sort of discussion to the dichotomy between movie critics
and people who actually go and see movies. The critics inevitably have
all sorts of snobby things to say about the movies which are best
attended. I'm not sure why anyone listens to any critic on any subject.

Paul



--- End Message ---
--- Begin Message ---
On Sat, 2009-05-16 at 10:48 +0100, Ashley Sheridan wrote:
> On Sat, 2009-05-16 at 02:25 -0400, Paul M Foster wrote:
> > On Fri, May 15, 2009 at 01:25:42PM -0400, PJ wrote:
> > 
> > > I know of no better place to ask. This may not be strictly a PHP issue,
> > > but...
> > > I am busting my hump trying to format rather large input pages with CSS
> > > and trying to avoid tables; but it looks to me like I am wasting my time
> > > as positioning with CSS seems an impossibly tortuous exercise. I've
> > > managed to do some pages with CSS, but I feel like I am shooting myself
> > > in the foot or somewhere...
> > > Perhaps I am too demanding. I know that with tables, the formatting is
> > > ridiculously fast.
> > > Any thoughts, observations or recommendations?
> > 
> > I think it's pretty telling that on a list of professionals who create
> > websites constantly, the overwhelming concensus is that for forms,
> > tables are the preferred solution.
> > 
> > I liken this sort of discussion to the dichotomy between movie critics
> > and people who actually go and see movies. The critics inevitably have
> > all sorts of snobby things to say about the movies which are best
> > attended. I'm not sure why anyone listens to any critic on any subject.
> > 
> > Paul
> > 
> > -- 
> > Paul M. Foster
> > 
> I think the argument of tables vs css can go a little deeper too. These
> days, sites should not only be developed with good clean code that
> validates, but semantic markup. If your client doesn't like/know what
> this is, just give it to them in terms of seo!

FWIW, everything I've read indicates that tables don't affect SEO.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
Just a draft i thought should not go unnoticed on the list :-) just cleaning
up.
OK,

How about a super efficient soln where each string is only converted once
and a fast sorting algorithm is used:

<?php

function time_sort($a, $b)  {
     static $now = time();

     if (strtotime($a, $now) == strtotime($b, $now)) {
         return 0;
     }
     return (strtotime($a, $now) < strtotime($b, $now) ? -1 : 1;
}

function sortTime($times) {

}
Tim-Hinnerk Heuer

http://www.ihostnz.com
Fred Allen  - "California is a fine place to live - if you happen to be an
orange."

2009/2/16 Shawn McKenzie <nos...@mckenzies.net>

> tedd wrote:
> > At 9:31 PM -0600 2/14/09, Shawn McKenzie wrote:
> >>
> >> Yeah, hif I had known that you wanted a function where you loop through
> >> your array twice, that would have done it.  Bravo.
> >
> > Shawn:
> >
> > I don't see another way. You go through the array converting string to
> > time (seconds), sort, and then convert back. You have to go through the
> > array more than once.
> >
> > Cheers,
> >
> > tedd
> >
> The "other way", is the most likely ultra-fast solution I posted.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Tom Worster wrote:

> imagine writing a script to run as a daemon reading data off the
> bottom of a log file that gets updated every few minutes and
> processing each new log line as they arrive.
> 
> i could exec("tail $logfile", $lines, $status) every now and then. or
> poll the file mtime and run exec("tail $logfile", $lines, $status)
> when it changes. there will be some lag due to the polling interval.
> 
> but it would be nice to not have to poll the file and somehow trigger
> the processing of the new line when the log file is written. but i'm
> not sure how to do that.
> 
> any ideas?

1) the inotify interface will alert you when a file or directory
changes. 

2) run tail -f logfile | <yourscript> and read from stdin. (not tested).

3) if you can change the logfile to a fifo, you're all set.


/Per


-- 
Per Jessen, Zürich (11.7°C)


--- End Message ---
--- Begin Message ---
On Fri, 2009-05-15 at 13:55 -0400, Bob McConnell wrote:
> From: Bastien Koert
> > On Fri, May 15, 2009 at 12:35 PM, Michael A. Peters <mpet...@mac.com>
> wrote:
> >> Paul M Foster wrote:
> >>> On Fri, May 15, 2009 at 10:21:22AM +0100, Peter Ford wrote:
> >>>
> >>>  Matt Graham wrote:
> >>>>
> >>>
> >>
> >>>> But why write an Excel spreadsheet - why not save the data in
> something
> >>>> more
> >>>> portable like CSV that ExCel and read and write to once you are
> back at
> >>>> base?
> >>>>
> >>>>
> >>> CSV doesn't export *formulas*, just the visible numbers.
> >>>
> >>
> >> gnumeric handles everything excel that I have ever needed, and is
> FOSS.
> >> I believe OpenOffice also does very well.
> >>
> >> That being said, you are more likely to find excel installed than
> either of
> >> those, excel is the spreadsheet standard at this point, and both
> those
> >> products mentioned handle most excel files, so saving as excel should
> (in
> >> most cases) be plenty portable.
> > 
> > unless you run into xlsx format office 2007...
> 
> From what I have heard so far, OOo.org is better at reading and writing
> xlsx than Office 2007 SP2 is with ODF. Early reviews suggest that
> Microsoft has shot themselves in the foot, again.
> 
> But what does this have to do with PHP?
> 
> Bob McConnell
> 
There are dozens of distros out there that are offered as portable app
solutions. You can run an entire OS from the USB key, and have the
open-source software on there that you need, like Fx (to use Firefox's
proper abbreviation), OOo, Gimp, etc. That way, it won't matter what the
end user has installed on their computer, as you have everything you
need right there.


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
Hi,

I am pretty new to PHP and I am trying to create a shopping cart. 

I keep on getting the below error when trying to show the shopping list. 

Any guidance that can be provided will be very much appreciated

Fatal error: Call to a member function query() on a non-object in 
C:\wamp\www\draft\basket.php on line 36

mysql_connect.php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("rum", $con);
?>

basket.php
<?php 
 include("mysql.class.php");
 include ("header.php");
 include ("mysql_connect.php");
  include ("functions.php");
 ?>
 <div id="shopping">
<h2>Rum Basket</h2>
<?php
    echo writeCart();
    ?>
 </div>
<div id="rumlist">
  <h2>Rum on Offer</h2>
  <?php
 
 $sql= 'SELECT * FROM spirits BY id';
  $result = $con->query($sql);
 $output[]= '<ul>';
 while ($row = $result->fetch()) {
 $output[] = '<li>'.$row['name'].': &pound;'.$row['price'].'<br/><a 
href="cart.php?action=add&id=
  '.$row['id'].'">Add to Cart</a></li>';
    }
    $output[] = '</ul>';
  echo join ('', $output);
   ?>
  </div>

</div>
<?php
 include("footer.html");

?>


cart.php

<?php 

 include ("header.php");
 
 include ("mysql_connect.php");
 
 include ("functions.php");
 


$cart = $_SESSION['cart'];


if(isset($_GET["action"]))
{ $action = $_GET["action"]; }
else
{ $action = ""; }


switch ($action) {
 case 'add':
  if ($cart) {
   $cart .= ','.$_GET['id'];
  } else {
   $cart = $_GET['id'];
  }
  break;
 case 'delete':
  if ($cart) {
   $items = explode(',',$cart);
   $newcart = '';
   foreach ($items as $item) {
    if ($_GET['id'] != $item) {
     if ($newcart != '') {
      $newcart .= ','.$item;
     } else {
      $newcart = $item;
     }
    }
   }
   $cart = $newcart;
  }
  break;
 case 'update':
 if ($cart) {
  $newcart = '';
  foreach ($_POST as $key=>$value) {
   if (stristr($key,'qty')) {
    $id = str_replace('qty','',$key);
    $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
    $newcart = '';
    foreach ($items as $item) {
     if ($id != $item) {
      if ($newcart != '') {
       $newcart .= ','.$item;
      } else {
       $newcart = $item;
      }
     }
    }
    for ($i=1;$i<=$value;$i++) {
     if ($newcart != '') {
      $newcart .= ','.$id;
     } else {
      $newcart = $id;
     }
    }
   }
  }
 }
 $cart = $newcart;
 break;
}
$_SESSION['cart'] = $cart;

?>

<div id="shopping">

<h2>Rum Basket</h2>

<?php
echo writeCart();
?>

</div>

<div id="contents">

<h2>Please Check Quantities...</h2>

<?php
echo showCart();
?>

<p><a href="basket.php">Back to Rum List</a></p>

</div>

</div>


<?php
 include("footer.html");

?>

functions.php

<?php
function writeCart() {
 $cart = $_SESSION['cart'];
 if (!$cart) {
  return '<p>There is no alcohol in your Rum Basket</p>';
 } else {
  // Parse the cart session variable
  $items = explode(',',$cart);
  $s = (count($items) > 1) ? 's':'';
  return '<p>There are<a href="cart.php">'.count($items).' item'.$s.' in your 
rum basket</a></p>';
 }
}
  
     function showCart() {
 $cart = $_SESSION['cart'];
 if ($cart) {
  $items = explode(',',$cart);
  $contents = array();
  foreach ($items as $item) {
   $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
  }
  $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
  $output[] = '<table>';
  foreach ($contents as $id=>$qty) {
   $sql = 'SELECT * FROM spirits WHERE id = '.$id;
   $result = $con->query($sql);
   $row = $result->fetch();
   extract($row);
   $output[] = '<tr>';
   $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" 
class="r">Remove</a></td>';
   $output[] = '<td>'.$name.'</td>';
   $output[] = '<td>&pound;'.$price.'</td>';
   $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" 
size="3" maxlength="3" ></td>';
   $output[] = '<td>&pound;'.($price * $qty).'</td>';
   $total += $price * $qty;
   $output[] = '</tr>';
  }
  $output[] = '</table>';
  $output[] = '<p>Grand total: &pound;'.$total.'</p>';
  $output[] = '<div><button type="submit">Update cart</button></div>';
  $output[] = '</form>';
 } else {
  $output[] = '<p>You shopping cart is empty.</p>';
 }
 return join('',$output);
}

?>




Many Thanks

Vee

--- End Message ---
--- Begin Message ---
On Sat, 2009-05-16 at 10:37 +0100, Vernon St Croix wrote:
> Hi,
> 
> I am pretty new to PHP and I am trying to create a shopping cart. 
> 
> I keep on getting the below error when trying to show the shopping list. 
> 
> Any guidance that can be provided will be very much appreciated
> 
> Fatal error: Call to a member function query() on a non-object in 
> C:\wamp\www\draft\basket.php on line 36

> basket.php
> <?php 
>  include("mysql.class.php");
>  include ("header.php");
>  include ("mysql_connect.php");
>   include ("functions.php");
>  ?>
>  <div id="shopping">
> <h2>Rum Basket</h2>
> <?php
>     echo writeCart();
>     ?>
>  </div>
> <div id="rumlist">
>   <h2>Rum on Offer</h2>
>   <?php
>  
>  $sql= 'SELECT * FROM spirits BY id';
>   $result = $con->query($sql);
>  $output[]= '<ul>';
>  while ($row = $result->fetch()) {
>  $output[] = '<li>'.$row['name'].': &pound;'.$row['price'].'<br/><a 
> href="cart.php?action=add&id=
>   '.$row['id'].'">Add to Cart</a></li>';
>     }
>     $output[] = '</ul>';
>   echo join ('', $output);
>    ?>
>   </div>
> 
> </div>
> <?php
>  include("footer.html");
> 
> ?>
> 
> [snip][/snip]
> 
> Many Thanks
> 
> Vee
The code you are having the error on is expecting a mysqli object, but
you are using mysql, which doesn't create objects that you access
methods and properties of.

Change the $result line in basket.php to $result = mysql_query($sql) and
in your while loop change it to use $row = mysql_fetch_array($result)


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
Thanks for that.

I have changed the code as you suggested, but there is an error on the while
loop.

*Warning*: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in *C:\wamp\www\draft\basket.php* on line *46*

when code is changed as below

while ($row = mysql_fetch_array($result)){



        $output[] = '<li>'.$row['name'].': &pound;'.$row['price'].'<br/><a
href="cart.php?action=add&id=
        '.$row['id'].'">Add to Cart</a></li>';

        }

        $output[] = '</ul>';

        echo join ('', $output);

        ?>

Many Thanks

Vee


2009/5/16 Ashley Sheridan <a...@ashleysheridan.co.uk>

> On Sat, 2009-05-16 at 10:37 +0100, Vernon St Croix wrote:
> > Hi,
> >
> > I am pretty new to PHP and I am trying to create a shopping cart.
> >
> > I keep on getting the below error when trying to show the shopping list.
> >
> > Any guidance that can be provided will be very much appreciated
> >
> > Fatal error: Call to a member function query() on a non-object in
> C:\wamp\www\draft\basket.php on line 36
>
> > basket.php
> > <?php
> >  include("mysql.class.php");
> >  include ("header.php");
> >  include ("mysql_connect.php");
> >   include ("functions.php");
> >  ?>
> >  <div id="shopping">
> > <h2>Rum Basket</h2>
> > <?php
> >     echo writeCart();
> >     ?>
> >  </div>
> > <div id="rumlist">
> >   <h2>Rum on Offer</h2>
> >   <?php
> >
> >  $sql= 'SELECT * FROM spirits BY id';
> >   $result = $con->query($sql);
> >  $output[]= '<ul>';
> >  while ($row = $result->fetch()) {
> >  $output[] = '<li>'.$row['name'].': &pound;'.$row['price'].'<br/><a
> href="cart.php?action=add&id=
> >   '.$row['id'].'">Add to Cart</a></li>';
> >     }
> >     $output[] = '</ul>';
> >   echo join ('', $output);
> >    ?>
> >   </div>
> >
> > </div>
> > <?php
> >  include("footer.html");
> >
> > ?>
> >
> > [snip][/snip]
> >
> > Many Thanks
> >
> > Vee
> The code you are having the error on is expecting a mysqli object, but
> you are using mysql, which doesn't create objects that you access
> methods and properties of.
>
> Change the $result line in basket.php to $result = mysql_query($sql) and
> in your while loop change it to use $row = mysql_fetch_array($result)
>
>
> Ash
> www.ashleysheridan.co.uk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Darrel St Croix

--- End Message ---

Reply via email to