Re: Where to learn about these topics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> In MySQL I would say... If you have data which has to be inserted in
> serveral tables, you must first check if all conditions are ok. So, do some
> selects to check if everythin in your database is ok, and after that,
> execute the query. But, when you really want to make complex database driven
> applications, choose PostgreSQL! This database is better build for
> complexity (and not only that ;) ), and supports transactions and
> references, and more stuff like that which can be really helpful to you...
> And when you compare MySQL against PostgreSQL... PostgreSQL is a heavy
> system compared with MySQL, also free, but when you look at the
> functionality: SUPERIOR 

But even with Postgresql I have the same situation. Let's say a user
wants to enter a new contact into the database. This contact lives in
a new city and has a new kind of relationship. To make that city and
relationship available, I need them in the related tables. Or I need
my form action to check for each one, insert if they are not there,
and then finally insert the new record. This last seems preferable
(one form), but no books seem to deal with the real world, only the
simplest, single-table cases...


>  $query = " SELECT * FROM table1, table2 WHERE table1.id = table2.id AND
> table1.value = 'value' OR table2.value = '' ORDER BY table1.name ";
>  
>  is less readable than:
>  
>  $query = " SELECT * FROM table1, table2
>                   WHERE table1.id = table2.id
>                              AND table1.value = 'value'
>                              OR table.value = ''
>                   ORDER BY table1.name   ";

Right-- but my question isn't about the query, but about the results.
Again, look at my result set:

+---------+----------+----------+-----------+-------+
| first   | last     | relation | city      | state |
+---------+----------+----------+-----------+-------+
| Chris   | Beks     | business | Fairbanks | AK    |
| Robert  | Hannon   | friend   | Fairbanks | AK    |
| Cindy   | Lott     | family   | Fresno    | CA    |
| Derryl  | Hartz    | business | Seattle   | WA    |
| Kirsten | O'Malley | friend   | Seattle   | WA    |
+---------+----------+----------+-----------+-------+

I want an output routine that does this:

CITY
  person
  person

CITY
  person

CITY 
  person

There has to be a more elegant way than making a new query for each
city-- which is what the query I mentioned above fixes... but is the
kind of code I have put, with its ugly indexes and counters really the
best way? This is another area where books always stop at the simplest
cases...

$currentcity = '';
$counter = 1;

while ($thisrow = mysql_fetch_array($result))
       {
       if ($currentcity <> $thisrow['city'])
               {
               if ($counter > 1)
                       {
                       echo '</blockquote>';
                       }
               echo '<h1>' . $thisrow['city'] . '</h1>';
               echo '<blockquote>';
               $currentcity = $thisrow['city'];
               }
       echo $thisrow['first'] . ' ' . $thisrow['last'] . '<br />';
       $counter++;
       }

c

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux