I need to create a form for this example in php. I need to have an unlimited number of seats with radio buttons next to each seat for the user to be able to select. BUT, when the user visits this page, it needs to pull the seats taken from the db and cross them out, rendering them inoperable without the radio button...

http://www.lanhorizon.com/step17.php

is there a way to do this? the logic seems easy, but actually making it work is another story

    Hey just wondering how your table is set up. Because this is really really easy. Just need to know what fields and table this is in. That would be the greatest thing you could provide us. I need to know so I can give you an example that is not just pesudo code. Ya dig?

      i currently only have 1 table called attendees...here is the create statement from that table:

      CREATE TABLE attendees (
      id tinyint(3) unsigned NOT NULL auto_increment,
      alias varchar(50) NOT NULL default '',
      seat varchar(5) NOT NULL default '',
      sold char(1) NOT NULL default '',
      PRIMARY KEY (id),
      UNIQUE KEY alias (alias),
      UNIQUE KEY seat (seat)
      ) TYPE=MyISAM

        well your ID is a tinyint so that is far from unlimited seating allowing only 255 seats.

        I would simulate a matricies like this:

        CREATE TABLE IF NOT EXISTS tblSeats (
          RowID TINYINT NOT NULL,
          ColID TINYINT NOT NULL,
          Alias VARCHAR(50) NOT NULL,
          Seat VARCHAR(5) NOT NULL,
          Sold  CHAR(1) NOT NULL,
          PRIMARY KEY (RowID,ColID),
          UNIQUE Alias (Alias),
          UNIQUE Seat (Seat)
        )
        

        Then in php it would be something like this

        <?php
        $max_rows = 100;
        $max_cols = 100;
        echo "<table>\n";
        for($i=1;$i<=$max_rows;$i++) {
            echo "  <tr>\n";
            for($j=1;$j<=$max_cols;$j++) {
                echo "<td>\n";
                $sql = "SELECT * FROM tblSeats WHERE RowID=$i AND ColID=$j":
                if($query = @mysql_query($sql)) {
                     //an entry exists for this seat, process it accordingly.
                } else {
                    //no entry exists for this sea, process it accordingly.
                } //end if
            } //end for $j
        } //end for $i
        ?>

          just as a test - i tried this:

          $max_rows = 16;
          $max_cols = 15;
          echo "<table>\n";
          for($i=1;$i<=$max_rows;$i++) {
          echo "<tr>\n";
          for($j=1;$j<=$max_cols;$j++) {
          $sql = "SELECT seat FROM attendees";
          if($query = @($sql)) {
          echo "<td>SOLD</td>\n";
          } else {
          echo "<td>OPEN</td>\n";
          }
          }
          }

          --- This code is also missing the closing <TR> and </TABLE> ---

          and this is the output (NOT what I am wanting):

          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD
          SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD

            1) I typed the code into the browser as an example. If you're going to knit pick my helpfulness I'll just not answer your questions anymore.

            2) You're assuming that if the entry exists in the table it must be sold. That's probably the issue try printing:

            mysql_result($query,'sold') instead

              1) Im not nitpicking. I greatly appreciate your helping me

              2) that still didnt work - it is saying not sold for the total number of rows and cols....

                
                $max_rows = 16; 
                $max_cols = 15; 
                echo "<table>\n"; 
                for($i=1;$i<=$max_rows;$i++) { 
                echo "<tr>\n"; 
                for($j=1;$j<=$max_cols;$j++) { 
                $sql = "SELECT seat FROM attendees"; 
                $query = @mysql_query($sql);
                
                if($row = mysql_fetch_array($query))
                { 
                echo "<td>SOLD</td>\n"; 
                } 
                else 
                { 
                echo "<td>OPEN</td>\n"; 
                } 
                } 
                } 
                
                

                  i must be doing something wrong - that code didnt work Shawon22 - it reverts back to the output above where it lists everything as sold...

                    well....it is getting closer...

                    i added in the where statement ( WHERE RowID=$i AND ColID=$j ) and it shows that it is working, BUT the seat that is in my db is #25 but the output of my script is making row1 and col1 the actual seat that is sold....

                      reverse the condition then

                      
                      $max_rows = 16;  
                      $max_cols = 15;
                      echo "<table>\n";
                      for($i=1;$i<=$max_rows;$i++) {
                      echo "<tr>\n";
                      for($j=1;$j<=$max_cols;$j++) {
                      $sql = "SELECT seat FROM attendees";
                      $query = @mysql_query($sql); if($row = mysql_fetch_array($query)) { echo "<td>OPEN</td>\n"; }
                      else
                      {
                      echo "<td>SOLD</td>\n"; }
                      }
                      }

                        now the first row and first column is open but the other 99 seats are sold

                        here is my code in case i have something all messed up

                        $max_rows = 16;  
                        $max_cols = 15;
                        echo "<table>\n";
                        for($i=1;$i<=$max_rows;$i++) { echo "<tr>\n"; for($j=1;$j<=$max_cols;$j++) { $sql = "SELECT seat FROM tblSeats WHERE RowID=$i AND ColID=$j"; $query = @mysql_query($sql); if($row = mysql_fetch_array($query)) { echo "<td>OPEN</td>\n"; } else { echo "<td>SOLD</td>\n"; } } echo "</tr>"; } echo "</table>";

                          could u post the datas for the first 5 or 10 rows?

                            I have 1 db table:

                            CREATE TABLE tblseats (
                            RowID tinyint(4) NOT NULL default '0',
                            ColID tinyint(4) NOT NULL default '0',
                            Alias varchar(50) NOT NULL default '',
                            Seat varchar(5) NOT NULL default '',
                            Sold char(1) NOT NULL default '',
                            PRIMARY KEY (RowID,ColID),
                            UNIQUE KEY Alias (Alias),
                            UNIQUE KEY Seat (Seat)
                            ) TYPE=MyISAM

                            with the values:

                            RowID = 1
                            ColID = 1
                            alias = RiverRat
                            seat = 25
                            sold = 1

                            here is the output of my script:

                            OPEN SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD SOLD

                            they all should be open except for the 25th one which is the seat I have in the db

                            • but it is using the ColID and RowID from the db to determine which seat is sold.....
                              
                              $max_rows = 16;   
                              $max_cols = 15;
                              echo "<table>\n";
                              for($i=1;$i<=$max_rows;$i++) { echo "<tr>\n"; for($j=1;$j<=$max_cols;$j++) { $sql = "SELECT seat FROM tblSeats WHERE RowID=$i AND ColID=$j"; $query = @mysql_query($sql); $row = mysql_fetch_array($query); if($row['sold'] == '1') echo "<td>OPEN</td>\n"; else echo "<td>SOLD</td>\n"; } echo "</tr>"; } echo "</table>";

                                still the same output

                                OPEN SOLD SOLD SOLD SOLD SOLD SOLD SOLD

                                $max_rows = 16;
                                $max_cols = 15;
                                echo "<table>\n";
                                for($i=1;$i<=$max_rows;$i++)
                                {
                                    echo "<tr>\n";
                                    for($j=1;$j<=$max_cols;$j++)
                                    {
                                        $sql = "SELECT seat, sold FROM tblSeats WHERE RowID=$i AND ColID=$j";
                                        $query = @mysql_query($sql);
                                		$row  = mysql_fetch_array($query);
                                		if($row['sold'] == '1')
                                		{
                                			echo "<td>OPEN</td>\n";
                                		}
                                
                                	else
                                	{
                                		echo "<td>SOLD</td>\n";
                                	}
                                }  
                                echo "</tr>";  
                                }  
                                echo "</table>";

                                  sorry its the other way around try this

                                  
                                  
                                  $max_rows = 16; 
                                  $max_cols = 15; 
                                  echo "<table>\n"; 
                                  for($i=1;$i<=$max_rows;$i++) 
                                  { 
                                      echo "<tr>\n"; 
                                      for($j=1;$j<=$max_cols;$j++) 
                                      { 
                                          $sql = "SELECT seat, sold FROM tblSeats WHERE RowID=$i AND ColID=$j"; 
                                          $query = @mysql_query($sql); 
                                          $row  = mysql_fetch_array($query); 
                                          if($row['sold'] == '1') 
                                          { 
                                              echo "<td>sold</td>\n"; 
                                          } 
                                  
                                      else 
                                      { 
                                          echo "<td>open</td>\n"; 
                                      } 
                                  }   
                                  echo "</tr>";   
                                  }   
                                  echo "</table>";

                                    well...i thought it was working.... maybe i asked the wrong question to begin with

                                    here is my code:

                                    <?php
                                    $alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
                                    $rowCount = 14;
                                    $totalSeats = 238;
                                    
                                    $connection = mysql_connect("localhost","******","******") or die ("Couldn't make connection.");
                                    $db = mysql_select_db("registration", $connection) or die ("Couldn't select database.");
                                    $sql = "SELECT seat, alias FROM attendees";
                                    $sql_result = mysql_query($sql,$connection) or die("Couldn't execute query.");
                                    
                                    $row = mysql_fetch_array($sql_result);
                                    $alias = $row['alias'];
                                    ?>
                                    
                                    <center>
                                    <table class="seattable" width="650">
                                    
                                    <?php
                                    for($i=0; $i<$totalSeats; $i++)
                                    {
                                    	$val = $i + 1;
                                    	if($i % $rowCount)
                                    	{
                                    		echo "<td align=\"center\" valign=\"middle\" ";
                                    	}
                                    
                                    else
                                    {
                                    	echo "</tr><tr>\n";
                                    	echo "<td align=\"center\" valign=\"middle\" class=\"rowheader\">";
                                    	echo $alphabet[($i / $rowCount)];
                                    	echo "</td>\n";
                                    	echo "<td align=\"center\" valign=\"middle\" ";
                                    }
                                    
                                    if(in_array($val, $row))
                                    {
                                    	echo "class=\"closed\"><a class=\"sold\" onMouseOver=\"self.status='SOLD TO ".$alias."'; return true;\" onMouseOut=\"self.status=' '; return true;\">";
                                    	echo "{$alias}";
                                    }
                                    
                                    else
                                    {
                                    	echo "class=\"open\">";
                                    	echo "<input type=\"radio\" name=\"seat\" value=\"{$val}\"><font class=\"avail\">{$val}</font>";
                                    }
                                    
                                    if($i % $rowCount + 1)
                                    {
                                    	echo "</td>\n";
                                    }
                                    
                                    else
                                    {
                                    	echo "</td></tr>\n\n";
                                    }
                                    }
                                    ?>
                                    </table>
                                    </center>
                                    

                                    here is the output results:

                                    http://www.lamerc.com/jay2/test2.php

                                    and there are 2 things here:

                                    1) I want to make th above look like this:
                                    http://www.lanhorizon.com/step17.php

                                    2) when pulling the seat from the db, it is only recognizing the first entry and not each one that has a seat value....

                                      On Astectics

                                          if($i % $rowCount + 1) 
                                          { 
                                              echo "</td>\n"; 
                                          } 
                                      
                                      else 
                                      { 
                                          echo "</td></tr>\n\n"; 
                                      } 
                                      

                                      at this point you need to check with x = 5*y where {0<y<4}

                                      so something like this:

                                      switch ($i*5) {
                                        case 1:
                                          break;
                                        case 2:
                                          break;
                                        case 3:
                                          break;
                                      }

                                      Then add in a spacer cell when the condition is met, like so:

                                      switch ($i*5) {
                                        case 1:
                                          echo "<td bgcolor=#EEEE>&nbsp;</td>\n";
                                          break;
                                        case 2:
                                          echo "<td bgcolor=#EEEE>&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
                                          break;
                                        case 3:
                                          echo "<td bgcolor=#EEEE>&nbsp;</td>\n";
                                      }

                                      as to your second question.

                                      You pull the first row and then loop always using that row, you need to pull a new row each time through the loop.

                                        Write a Reply...