Re: loop problem

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

 



I think that a foreach() loop would help you handle some of this problem.
Unfortunately, as it's early (or late, since I haven't slept), I haven't the
energy to draw up an example.

Also, and I say this in the kindest way, try to clean up the code.  You open and
close PHP tags so many times that everything is very difficult to read.  Little
things like this can make it easy to overlook otherwise obvious errors, as I
well know from personal experience.  While that doesn't seem the case here, it
could be at a later point in time.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


----- Original Message -----
From: "mark hurty" <hurty@mac.com>
To: <php-db@lists.php.net>
Sent: Thursday, 22 May, 2003 00:42
Subject:  loop problem


I am trying to loop through the results of two queries to create a
table showing available ticket prices for a group of events. The
results of the queries are returning the expected results, but each
ticket price is repeated under the event heading multiple times. If
there are three events on the page, there will be three rows of each
price, If there are four events, there are four rows of the prices. In
every other respect the query works as desired. What am I doing wrong.
Note that there are nested "while" loops.

as an example, the resulting page I want looks like this:

PROGRAM

Event A /  Venue / Date
   Ticket price A1
   Ticket price A2

Event B / Venue / Date
   Ticket Price B1
   Ticket Price B2
   Ticket Price B3

Event C
   Ticket Price C1
   Ticket Price C2
   Ticket Price C3

But the resulting page that I'm seeing looks like this:

PROGRAM

Event A /  Venue / Date
   Ticket price A1
   Ticket price A1
   Ticket price A1
     Ticket price A2
     Ticket price A2
     Ticket price A2

Event B / Venue / Date
   Ticket Price B1
   Ticket Price B1
   Ticket Price B1
    Ticket Price B2
    Ticket Price B2
    Ticket Price B2
     Ticket Price B3
     Ticket Price B3
     Ticket Price B3

Event C
   Ticket Price C1
   Ticket Price C1
   Ticket Price C1
     Ticket Price C2
     Ticket Price C2
     Ticket Price C2


> // Get a connection to the database
>
> $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
>
>
> // select the events in this program (events have subevents)
> // in most cases there are two types of events - encounters and
> concerts
> // encounters and concerts are sub events
>
> $resultListA = mysql_query("select * from events
> inner join subEvents on events.groupName = subEvents.seGroup
> where events.groupName='$groupBlock'
> ");
>     $rowA = mysql_fetch_array($resultListA);
>
>   ?>
> <h1><?php echo $rowA["groupDesc"]; ?></h1>
> <table>
>  <?php
>
>      // we loop through the sub events and make a row with the
> subevent information
>
>   mysql_data_seek($resultListA,0);
>   while ($rowA = mysql_fetch_array($resultListA))
>     { $Event = $rowA["seSKU"];
>
>
>       ?>
>   <tr><td>
>     <?php echo $rowA["seDesc"]; ?><br />
>     <?php echo $rowA["seVenue"]; ?><br />
>     <?php echo date ("l, F j, Y", mktime ( 0, 0, 0,
> substr($rowA["seDate"], 5,2), substr($rowA["seDate"], 8,2),
> substr($rowA["seDate"], 0,4))); ?><br />
>    </td></tr>
>    <?php
>
>      // we loop through the tickets availale for each subevent
>      // and make a row for each ticket price under the appropriate sub
> event
>
>    $resultList = mysql_query("select * from subEvents inner
> join tickets
>                      on subEvents.seGroup = '$groupBlock'
>                      where tickets.itemSubGroup = '$Event'
>                 ");
>
>                   $row = mysql_fetch_array($resultList);
>
>             mysql_data_seek($resultList,0);
> while ($row = mysql_fetch_array($resultList))
>     {
>     ?>
>        <tr><td>
> <?php echo $row["itemName"]; ?>
> <?php echo $row["itemSubGroup"]; ?>
> <a href="orderCart.php?action=add_item&id=<?php echo
> $row["itemId"]; ?>&qty=1"><?php echo $row["itemName"]; ?> | $<?php
> echo $row["itemPrice"]; ?></a>
>    </td></tr>
>
>
>      <?php
>      }
> }
> ?>
> </table>

the queries are extracting the right data from the tables.
--
mark hurty  |  mark@hurty.com  |  309.764.0911


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




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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux