473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Showing data too many times

New problem ;). I got script running and showing projects, now i'm trying to
show category for every project from another table. I want to do this in new
page. Everything is fine except ;))... it shows the data in according with
how many projects i have. So if i have 3 project da data from category table
is shown three times, if two projects it's shown two times etc.
The code is following:

<?php
require('config.php');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or
die ('Could not connect to MySQL database.' .mysql_error());
mysql_select_db (SQL_DB, $conn);
$display_block = "<h1>$project_name</h1>
<P>Select a Category to see details.</P>";

//validate category
$cat_id_info = isset($_GET['id']) ? intval($_GET['id']) : 0;
$get_info = "SELECT
category.id,
category.project_id,
category.cat_name,
category.cat_desc,
project.project_name,
project.id
FROM
category,
project
WHERE
category.project_id = $cat_id_info
ORDER BY category.cat_name";
$result = mysql_query($get_info) or die (mysql_error());
$num_category = mysql_num_rows($result);

$display_block .= "<a href=\"proba_link.php\">Back</a></strong></p>";
if (mysql_num_rows($result) < 1) {
$display_block = "<P><em>BLABLA.</em><br>
<a href=\"proba_link.php\">Back</a></strong></p>";
} else {

while ($cat = mysql_fetch_array($result)) {
$cat_id = $cat[id];
$cat_name = strtoupper(stripslashes($cat[cat_name]));
$cat_desc = stripslashes($cat[cat_desc]);

$display_block .= "<p><strong>$cat_name</strong>
<br>$cat_desc</p>";

}
}
?>
<HTML>
<HEAD>
<TITLE>Navtec Marine</TITLE>
</HEAD>
<BODY>
<?

print $display_block;

?>
</BODY>
</HTML>

Tnx in advance, best regards
Igor Slivka
Jul 17 '05 #1
1 1656
Igor Slivka wrote:
New problem ;). I got script running and showing projects, now i'm trying
to show category for every project from another table. I want to do this
in new page. Everything is fine except ;))... it shows the data in
according with how many projects i have. So if i have 3 project da data
from category table is shown three times, if two projects it's shown two
times etc. The code is following:
<snip> $get_info = "SELECT
category.id,
category.project_id,
category.cat_name,
category.cat_desc,
project.project_name,
project.id
FROM
category,
project
WHERE
category.project_id = $cat_id_info
ORDER BY category.cat_name";


You haven't joined the category and project tables so your getting a
cartesian product. Guessing the structure of your data, I would try adding
AND project_id=project.id
in the where clause.

'$cat_id_info' is badly named since it references a project not a category
(either that or the names of your other fields are bad).

HTH

C.
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marcin Floryan | last post by:
Hello! My question regards opening (and re-opening) Form and the Load event. I have a main form (frmMain) and I also have a data form (frmData). In the main form I have created: Private...
5
by: Don Sealer | last post by:
I have a database that I need to track certain measurements numerous times per day. I need to record several aspects like, length, width, thickness, plus a few other things. I've been recording...
9
by: C3 | last post by:
I have to process some data in C that is given to me as a char * array. I have a fairly large number of substrings (well, they're not actually printable, but let's treat them as strings) that I...
14
by: beginner10 | last post by:
How can i changhe this code showing how many persons i saved to the file? And it prints pretty much rubbish. Where is the problem? #include <stdio.h> int main() { int i; FILE *data_file;...
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
4
by: Wayne | last post by:
I have posted this problem a couple of times over the last few years but have been unable to find a solution that works. Sometimes charts in reports will display showing the design data instead of...
14
by: Dustan | last post by:
http://dustangroups.googlepages.com/privateattributesinpython This is something that I just threw together this morning, after a eureka moment. It's a way of creating private class attributes and...
6
waynetheengineer
by: waynetheengineer | last post by:
Hi all, I have a database that has two tables: 1 table shows different types of animals: e.g. rabbits, bears, birds, etc. a 2nd table that links to each animal type that has individual animals...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.