Jump to content

Recommended Posts

I have a table in Mysql database that I need some help on creating my query in PHP. (dont worry

about the html) The user has an admin area where he adds products to the database.I do not know

the name of the product that are added. I need to have the data displayed on the web page like

this:

manufacture x
---------------------

Manufacturer x | ID | Title | Year | Price |
---------------------------------------------------------
| x | 3 | RH1 | 2005 | 110 |
| x | 9 | WR7 | 1997 | 120 |
| x | 7 | G69 | 1992 | 150 |

manufacture y
---------------------

Manufacturer y | ID | Title | Year | Price |
---------------------------------------------------------
| y | 2 | YH1 | 2003 | 110 |
| y | 1 | HR7 | 1999 | 120 |
| y | 5 | E69 | 1995 | 150 |


manufacture z
---------------------

Manufacturer z | ID | Title | Year | Price |
---------------------------------------------------------
| z | 4 | LD1 | 2001 | 100 |
| z | 6 | HD7 | 1990 | 120 |
| z | 8 | JR89 | 1980 | 75 |



----------------------------------------------------------------------------

My Database table looks like this:


ID | Manufacturer | TITLE | Year | Price |

1 | y | HR7 | 1999 | 120 |
2 | y | YH1 | 2003 | 110 |
3 | x | RH1 | 2005 | 110 |
4 | Z | LD1 | 2001 | 100 |
5 | y | E69 | 1995 | 150 |
6 | Z | HD7 | 1990 | 120 |
7 | x | G69 | 1992 | 150 |
8 | z | JR89 | 1980 | 75 |
9 | x | WR7 | 1997 | 120 |


---------------------------------------------------------------------------


My PHP looks like this:



<?php
$maxRows_mydata = 100;
$pageNum_mydata = 0;
if (isset($_GET['pageNum_mydata'])) {
$pageNum_mydata = $_GET['pageNum_mydata'];
}
$startRow_mydata = $pageNum_mydata * $maxRows_mydata;

mysql_select_db($db_name, $link);
$query_mydata = "SELECT DISTINCT manufacturer, id, title,year,price,FROM my_product WHERE NOT

(manufacturer IS NULL) ORDER BY manufacturer DESC";
$query_limit_mydata = sprintf("%s LIMIT %d, %d", $query_mydata, $startRow_mydata,

$maxRows_mydata);
$mydata = mysql_query($query_limit_mydata) or die(mysql_error());
$row_mydata = mysql_fetch_assoc($mydata);

if (isset($_GET['totalRows_mydata'])) {
$totalRows_mydata = $_GET['totalRows_mydata'];
} else {
$all_mydata = mysql_query($query_mydata);
$totalRows_mydata = mysql_num_rows($all_mydata);
}
$totalPages_mydata = ceil($totalRows_mydata/$maxRows_mydata)-1;
?>



---------------------------------------
<td valign="middle">
<p class="header1"></p>
<?php echo $row_mydata['manufacturer']; ?></td>

<?php do { ?>
<td align="center" valign="middle" bgcolor="#5080a8" class="Black_copy">Manufacturer</td>
<td align="center" valign="middle" bgcolor="#5080a8" class="Black_copy">ID</td>
<td align="center" valign="middle" bgcolor="#5080a8" class="Black_copy">Title</td>
<td align="center" valign="middle" bgcolor="#5080a8" class="Black_copy"> Year </td>
<td align="center" valign="middle" bgcolor="#5080a8" class="Black_copy">Price </td>
--------------------------------------



<td>
<a href="http://www.mywebsite.com/products/inventory.php?id=<?php echo $row_mydata['id']; ?>"

class="listing">
<?php echo $row_mydata['manufacturer']; ?></td>
<td align="center" class="listing"><?php echo $row_mydata['title']; ?> </a></td>
<td align="center" class="listing"><?php echo $row_mydata['year']; ?></td>
<td align="center" class="listing"><?php echo $row_mydata['hull_type']; ?></td>



<?php } while ($row_mydata = mysql_fetch_assoc($mydata)); ?>



<?php mysql_free_result($mydata);?>
---------------------------------------------------------------


This almost works but it only list the first manufacturer as a title and then list all fo the

records as it loops through the code.
so I only get one header and one table with all of the listings on the web page.

Any insite would be appreciated.

Thanks
Link to comment
https://forums.phpfreaks.com/topic/12757-php-mysql-help/
Share on other sites

Try chaning :
[code]<td align="center" class="listing"><?php echo $row_mydata['title']; ?> </a></td>
<td align="center" class="listing"><?php echo $row_mydata['year']; ?></td>
<td align="center" class="listing"><?php echo $row_mydata['hull_type']; ?></td>[/code]
To:
[code]while ($row_mydata = mysql_fetch_assoc($mydata)) {
<td align="center" class="listing"><?php echo $row_mydata['title']; ?> </a></td>
<td align="center" class="listing"><?php echo $row_mydata['year']; ?></td>
<td align="center" class="listing"><?php echo $row_mydata['hull_type']; ?></td>
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/12757-php-mysql-help/#findComment-48941
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.