Jump to content


Photo

PHP Mysql Help


  • Please log in to reply
1 reply to this topic

#1 greybeard

greybeard
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 June 2006 - 08:02 PM

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...ry.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


#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 24 June 2006 - 12:03 AM

Try chaning :
<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>
To:
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>
}


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users