Grouping issues

good day all, i apologise in advance if my code is poorly structured. i am having some issues with grouping some tables on a page there are headings such as

Bedside
table here

Bedside
table here

Hallway
table here

etc.

i need the two bedsides to group under one heading but display the information in each table. my code looks like the following. (again i apologise, i have been self teaching)

[php]

<? $query = "Select Bookcase_ID from Books where Books.username = '$sessionuser' Group BY Bookcase_ID "; $result = mysql_query ($query) or die(mysql_error()); ?> My Books table, th, td { border:1px solid black; }

Welcome

 <h1> Your books </h1> 

 
 <?php
 while ($row = mysql_fetch_array($result)) {
 
 $bookcasz = $row{'Bookcase_ID'};

	$query = "select *
    from Books
	where Books.username = '". $_SESSION['username']. "'
	AND Bookcase_ID = '$bookcasz'";
		$result2 = mysql_query ($query);
		while ($rows = mysql_fetch_array ($result2)){

		  ?>
 <tr>
   <th align = "left"> ISBN </th>
   <th align = "left"> Title </th>
   <th align = "left"> Author </th>
   <th align = "left"> Genre </th>
   <th align = "left"> Price </th>
   <th align = "left"> Bookcase </th>
   <th align = "left"> Bk Shelf Number </th>
   <th align = "left"> Description </th>
   <th align = "left"> Username </th>
 </tr>
  <?
    echo"<tr>";   /* not sure i need this line */
	echo"<h2>" .$bookcasz. "</h2>";
	 echo" <td>".   $rows [0] . " </td>";?>
	  <td> <?php echo $rows [1]; ?> </td>
	  <td> <?php echo $rows [2]; ?> </td>
	  <td> <?php echo $rows [3]; ?> </td>
	  <td> <?php echo $rows [4]; ?> </td>
	  <td> <?php echo $rows [5]; ?> </td>
	  <td> <?php echo $rows [6]; ?> </td>
	  <td> <?php echo $rows [7]; ?> </td>
	  <td> <?php echo $rows [8]; ?> </td>
	 <td align = "center"><a href = "DBdelete.php?txtisbn=<?php echo $rows [0]; ?>"> Delete </a> / <a href = "DBedit.php?txtisbn=<?php echo $rows [0]; ?>">Edit</a></td>
	</tr></br>
	
	<?}
	
	}


	
?>
[/php]

can anyone tell me where i am going wrong aside from mixing html and php badly

Well for starters you are using obsolete code in using mysql, you should be using mysqli or PDO (My Recommendation). This will enable you to use prepared statements and I find it also keeps you better organized.

As for intermingling PHP and HTML, a rule of thumb is to try to keep most of the PHP at the top of the page and the HTML below that. You should also try to keep the code formatted, so it will be easier to read and debug. There are times when you will have to intermingle PHP and HTML together as in your case, but you still could keep it manageable.

You are also using old html, look into html5.

What is your table structure? I would do this using sql, and group the location of the book to find what should be displaying in what table.

Sponsor our Newsletter | Privacy Policy | Terms of Service