/    Sign up×
Community /Pin to ProfileBookmark

Problem with displaying data

Hi, i have product name which is common for all product type. I am trying to display data in table from database, product name should come as a single row. Pls help me to solve this problem

i would like to display like this

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
<table width=”620″ border=”1″>
<tr>
<td width=”130″>Product Name </td>
<td width=”143″>Product Type</td>

</tr>
<tr>
<td>Coated </td>
<td>Silk</td>
</tr>
<tr>
<td></td>

<td>Gloss </td>
</tr>
<tr>
<td></td>
<td>Cast Coated </td>
</tr>
<tr>
<td></td>
<td>Matt </td>
</tr>
<tr>
<td></td>
<td> Part Mechanical </td>
</tr>
<tr>
<td></td>
<td> Gloss Digital </td>
</tr>
<tr>
<td></td>
<td> Silk Digital </td>
</tr>
<tr>
<td></td>
<td> Gloss One Sided </td>
</tr>
</table>
</body>
</html>[/code]

Here is my code

[code=php]<?php
include(‘config.php’);

$query= “select * from jos_list where category_id=’43’ “;

$result = mysql_query($query);
$Cat = mysql_query(“Select * from jos_list_categories where id=’43′”);
$Cat_Row = mysql_fetch_array($Cat);
?>
<table border=”1″>
<tr>
<td>Product Name</td>
<td>Product Type</td>
</tr>
<?php
while($row=mysql_fetch_array($result))
{

?>
<tr>
<td><?php echo $Cat_Row[‘title’]?></td>
<td><?php echo $row[‘title’];?></td>
</tr>
<?php
}
?>
</table>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiMay 22.2009 — So what's the problem you are having?

BTW You don't need to make two different queries, you can just use an INNER JOIN (or LEFT JOIN depending on which is more appropriate):

SELECT * FROM jos_list AS j INNER JOIN jos_list_categories AS c ON j.category_id = c.id WHERE c.id = 43
Copy linkTweet thisAlerts:
@kavionlyauthorMay 22.2009 — Problem here is, i don't want to display product name in multiple rows it should be in a single row and the corresponding product types should come in multiple rows.I used join query but still same problem


Which will look something like this


[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="620" border="1">
<tr>
<td width="130">Product Name </td>
<td width="143">Product Type</td>

</tr>
<tr>
<td>Coated </td>
<td>Silk</td>
</tr>
<tr>
<td></td>

<td>Gloss </td>
</tr>
<tr>
<td></td>
<td>Cast Coated </td>
</tr>
<tr>
<td></td>
<td>Matt </td>
</tr>
<tr>
<td></td>
<td> Part Mechanical </td>
</tr>
<tr>
<td></td>
<td> Gloss Digital </td>
</tr>
<tr>
<td></td>
<td> Silk Digital </td>
</tr>
<tr>
<td></td>
<td> Gloss One Sided </td>
</tr>
</table>
</body>
</html>
[/code]



[code=php]<?php
include('config.php');

$query= "select jos_list_categories.title as pname,jos_list.* from jos_list_categories, jos_list where category_id='43' and jos_list_categories.id=jos_list.category_id";

$result = mysql_query($query);
?>
<table border="1">
<tr>
<td>Product Name</td>
<td>Product Type</td>
</tr>
<?php
while($row=mysql_fetch_array($result))
{

?>
<tr>
<td><?php echo $row['pname']?></td>
<td><?php echo $row['title'];?></td>
</tr>
<?php
}
?>
</table>
[/code]
Copy linkTweet thisAlerts:
@MindzaiMay 22.2009 — The join query won't solve your problem, it just makes your code simpler. Nobody can solve your problem because you haven't said what your problem is!
×

Success!

Help @kavionly spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...