/    Sign up×
Community /Pin to ProfileBookmark

Join Table with same field name

Hi,

i’ve to work with a DB already create … i’m using a JOIN to output data from 3 table but in each table, there’s a field called ‘Name’

How could I retreived data from the three field ‘Name’ and echo it into php loop ??

ex:

Table 1 name = <?=$row[‘Name’]?>
Table 2 name = <?=$row[‘Name’]?>
Table 3 name = <?=$row[‘Name’]?>

Thank

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehNov 16.2005 — [code=php]// first you do the 3 queries (using different variable names of course)

$row_one = mysql_fetch_array($query_one_result);
$row_two = mysql_fetch_array($query_two_result);
$row_three = mysql_fetch_array($query_three_result);

//Now print them

echo $row_one['name'].' -'.$row_two['name'].' -'.$row_three['name'];[/code]
Copy linkTweet thisAlerts:
@turbauthorNov 16.2005 — Ok but how if I've got only 1 query, like that :

$sql = "SELECT * FROM Courses INNER JOIN CourseType ON Courses.TypeID = CourseType.TypeID";

$result = mysql_query($sql) or die('03_ '.mysql_error());

(actually there's only two tables)

Sorry, but I don't really understand your answer

Thank
Copy linkTweet thisAlerts:
@ShrineDesignsNov 16.2005 — use aliases in your sql statement, if you try to select all "*" from two or more tables and a field name occurs more than once, mysql will throw an errorSELECT c.*, t.Name AS <span><code>tName</code></span> FROM <span><code>Courses</code></span> AS <span><code>c</code></span> INNER JOIN <span><code>CourseType</code></span> AS <span><code>t</code></span> ON c.TypeID = t.TypeIDor (shorthand)SELECT c.*, t.Name <span><code>tName</code></span> FROM <span><code>Courses</code></span> <span><code>c</code></span> INNER JOIN <span><code>CourseType</code></span> <span><code>t</code></span> ON c.TypeID = t.TypeID
×

Success!

Help @turb 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 4.29,
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,
)...