Menu
__(Added `[code]…[/code]
I have two tables in db Tenses and tensecategories … Now i want to use inner join and display values on the page ?
[code]<?php
$getcat = mysqli_query($conn, “SELECT * FROM tensecategory t, tenses c WHERE t.tenid=c.pktenseid”);
$i =1;
while($cat = mysqli_fetch_assoc($getcat))
{
$id = $cat[‘pkcategoryid’];
$cat_name = $cat[‘cat_name’];
$tenid = $cat[‘tense_name’];
//$tensess = $cat[‘tense_name’];
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $cat_name; ?></td>
<td><?php echo $tenid; ?></td>
teneid
>@jasmine381#1612603 tenid id values 1,2 3 is the multiple ids from tenses table
<i>
</i>... where find_in_set(c.pktenseid, t.tenid) > 0 ...
$sql = "SELECT t.name, c.catid, c.catname FROM tenses t, tensecategory c WHERE t.catid=c.catid";
$result = $pdo->query($sql);
var_dump($result->rowCount());
$tenseinfo = [];
foreach ($result as $row) {
if (!isset($tenseinfo[$row['catid']])) {
$tenseinfo[$row['catid']] = ['catname' => $row['catname'], 'tenses' => [$row['name']]];
} else {
$tenseinfo[$row['catid']]['tenses'][] = $row['name'];
}
}
var_dump($tenseinfo);
tenses.tense_category_id
you should be associating from the Tenses table to the TenseCategory table, not the other way around as you're doing now.[/quote]I did so in my attempt.
>@Sempervivum#1612658 I did so in my attempt.
$result = $pdo->query($sql);
$tenseinfo = [];
foreach ($result as $row) {
if (!isset($tenseinfo[$row['catid']])) {
$tenseinfo[$row['catid']] = ['catname' => $row['catname'], 'tenses' => [$row['name']]];
} else {
$tenseinfo[$row['catid']]['tenses'][] = $row['name'];
}
}
var_dump($tenseinfo);
echo '<table>';
foreach ($tenseinfo as $catid => $data) {
echo '<tr><td>' . $catid . '</td>';
$tensesimpl = implode(', ', $data['tenses']);
echo '<td>' . $tensesimpl . '</td>';
}
echo '</table>';
<table><tr><td>2</td><td>Present Tense, Present Perfect, Imperfect</td><tr><td>17</td><td>Preterite, Past Perfect, Subjunctive</td></table>
$sql = "SELECT t.name, c.catid, c.catname FROM tenses t, tensecategory c WHERE t.catid=c.catid";
$getcat = mysqli_query($conn, $sql);
$tenseinfo = [];
while ($row = mysqli_fetch_assoc($getcat)) {
if (!isset($tenseinfo[$row['catid']])) {
$tenseinfo[$row['catid']] = ['catname' => $row['catname'], 'tenses' => [$row['name']]];
} else {
$tenseinfo[$row['catid']]['tenses'][] = $row['name'];
}
}
var_dump($tenseinfo);
echo '<table>';
foreach ($tenseinfo as $catid => $data) {
echo '<tr><td>' . $catid . '</td>';
echo '<td>' . $data['catname'] . '</td>';
$tensesimpl = implode(', ', $data['tenses']);
echo '<td>' . $tensesimpl . '</td></tr>';
}
echo '</table>';
Note that this will work only when using the modifyed structure of the tables I posted previously.<?php<br/>
$sql = "SELECT t.tense_name, c.tenid, c.cat_name FROM tenses t, tensecategory c WHERE t.pktenseid=c.tenid";<br/>
$getcat = mysqli_query($conn, $sql);<br/>
$tenseinfo = [];<br/>
while ($row = mysqli_fetch_assoc($getcat)) {<br/>
if (!isset($tenseinfo[$row['tenid']])) {<br/>
$tenseinfo[$row['tenid']] = ['cat_name' => $row['cat_name'], 'tenses' => [$row['tense_name']]];<br/>
} else {<br/>
$tenseinfo[$row['tenid']]['tenses'][] = $row['tense_name'];<br/>
}<br/>
}<br/>
//var_dump($tenseinfo);<br/>
echo '<table>';<br/>
foreach ($tenseinfo as $catid => $data) {<br/>
echo '<tr><td>' . $catid . '</td>';<br/>
echo '<td>' . $data['cat_name'] . '</td>';<br/>
$tensesimpl = implode(', ', $data['tenses']);<br/>
echo '<td>' . $tensesimpl . '</td></tr>';<br/>
}<br/>
echo '</table>';<br/>
?>
User will create tenses or tensescategory[/quote]If the user does it there shurely exists a form and a PHP script that reads the GET or POST variables and enters them to the database?
User will create tenses or tensescategory as you see on my last screenshot where i combine 2 tables and final print page OUTPUT..[/quote]Does this mean that the user enters the string '1,2,4' into some input element? Can you post the relevant part of the form where the user inputs the tenses?