Jump to content

Merch list in table with limited merch per table row


Guber-X

Recommended Posts

Im looking to update the way my merchandise page lists items.

 

Im trying to make it so the query will list items in a table and have it query 6 items in one row before it makes a second table row.

 

heres my code i have now, but it lists them all horizontally down the page cuz of how i have it. but i'd like to change it to my explanation above

i know i will have to change it all into a table query but how to get it to list 6 items before it makes next row is what i dont know how to do.

<?php
                         if('/merch.php'==$_SERVER['PHP_SELF'])
			{
				$catquery = mysql_query('SELECT * FROM merch GROUP BY merch_cat')
					or die('mySQL Query Failed: '.mysql_error());
				$num_rows = mysql_num_rows($catquery);
				if($num_rows==0){
					echo 'Nothing Here';
					break;
				}
				echo '<center><font size="6">';
				while($row = mysql_fetch_array($catquery)){
					list($id, $merch_name, $merch_image, $merch_cat, $merch_info, $buy, $price) = $row;
					echo ': <font class="myFont"><a href="merch.php?list=false&merch_cat='.$merch_cat.'">'.$merch_cat.'</a></font> ';
				}
				echo ':</font><br />';
				echo '<center>Select a Category</center>';
				echo '<br /><br />';
				echo '<div><font class="myFont" size="6">New Items</font></div>';
				$newquery = mysql_query('SELECT * FROM merch ORDER BY id DESC LIMIT 4')  //Obviously im going to change the limit when i get this working
					or die('New Query Failed: '.mysql_error());
				while($rows = mysql_fetch_array($newquery)){
					list($id, $merch_name, $merch_image, $merch_cat, $merch_info, $buy, $price) = $rows;
					echo '<a href="merch.php?list=true&merch_cat='.$merch_cat.'&id='.$id.'">'.$merch_name.'<br />';
					echo '<img src="media/merch/'.$merch_image.'-thumb.png" border="0"></a>';
					echo '<br /><br />';
				}

			}
			break;
?>

Link to comment
Share on other sites

well, i figured this crap out lol... surprised on how easy it was actually :P

 

<?php

                         if('/merch.php'==$_SERVER['PHP_SELF'])
			{
				$catquery = mysql_query('SELECT * FROM merch GROUP BY merch_cat')
					or die('mySQL Query Failed: '.mysql_error());
				$num_rows = mysql_num_rows($catquery);
				if($num_rows==0){
					echo 'Nothing Here';
					break;
				}
				echo '<center><font size="6">';
				while($row = mysql_fetch_array($catquery)){
					list($id, $merch_name, $merch_image, $merch_cat, $merch_info, $buy, $price) = $row;
					echo ': <font class="myFont"><a href="merch.php?list=false&merch_cat='.$merch_cat.'">'.$merch_cat.'</a></font> ';
				}
				echo ':</font><br />';
				echo '<center>Select a Category</center>';
				echo '<br /><br />';
				echo '<div><font class="myFont" size="6">New Items</font></div>';
				$newquery = mysql_query('SELECT * FROM merch ORDER BY id DESC LIMIT 6')
					or die('New Query Failed: '.mysql_error());
				$counter = 0;
				echo '<table width=900><tr>';
				while($rows = mysql_fetch_array($newquery)){
					list($id, $merch_name, $merch_image, $merch_cat, $merch_info, $buy, $price) = $rows;
					if ($counter % 3==0) { 
				        echo '</tr>';
				        echo '<tr>';
				    }
						echo '<td align="center">';
						echo '<a href="merch.php?list=true&merch_cat='.$merch_cat.'&id='.$id.'">'.$merch_name.'<br />';
						echo '<img src="media/merch/'.$merch_image.'-thumb.png" border="0"></a>';
						echo '</td>';
						$counter++;
				}
				echo '</tr>';
			}
			echo '</table>';
			break;
			}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.