Ok sorry guys for blabbering earlier this is the full code I have
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
echo "<p>Query<p>";
// Query Gets Tag IDs where the Categroy and Tag Alias is the same
$TagID = "SELECT at6ln_discuss_tags.id, at6ln_discuss_tags.title
FROM at6ln_discuss_tags
INNER JOIN at6ln_discuss_category ON at6ln_discuss_tags.alias = at6ln_discuss_category.alias";
$resultTagID = $conn->query($TagID);
//Query Gets Posts IDs where the posts Categroy ID and Category ID are the same
$PostID = "SELECT at6ln_discuss_posts.id
FROM at6ln_discuss_posts
INNER JOIN at6ln_discuss_category ON at6ln_discuss_posts.category_id = at6ln_discuss_category.id";
$resultPostID= $conn->query($PostID);
//Query Gets catergory ID where the Categroy and Tag Alias is the same
$CategoryID = "SELECT at6ln_discuss_category.id
FROM at6ln_discuss_category
INNER JOIN at6ln_discuss_tags ON at6ln_discuss_category.alias = at6ln_discuss_tags.alias";
$resultCategoryID= $conn->query($CategoryID);
//Query Gets Posts catergory ID where the Categroy and Tag Alias is the same
$PostsCategoryID = "SELECT at6ln_discuss_posts.category_id, at6ln_discuss_category.alias
FROM at6ln_discuss_posts, at6ln_discuss_category
WHERE (at6ln_discuss_posts.category_id = at6ln_discuss_category.id)";
$resultPostsCategoryID= $conn->query($PostsCategoryID);
//Query Gets catergory Alais where the Categroy and Tag Alias is the same
$PostsCategoryAlias = "SELECT at6ln_discuss_category.alias
FROM at6ln_discuss_category
INNER JOIN at6ln_discuss_tags ON at6ln_discuss_category.alias = at6ln_discuss_tags.alias";
$resultPostsCategoryAlias= $conn->query($PostsCategoryAlias);
$sql= "INSERT INTO at6ln_discuss_posts_tags (post_id,tag_id) VALUES ($idposts,$TagID)";
if ($resultTagID->num_rows > 0) {
echo "<table>";
echo "<tr>";
echo "<th> Post ID </th>";
echo "<th> Tag ID </th>";
echo "<th> Post Catergory ID </th>";
echo "</tr>";
// output data of each row
while($posts = $resultPostID->fetch_assoc() ) {
// output data of each row
$category = $resultCategoryID->fetch_assoc();
$postscatID = $resultPostsCategoryID->fetch_assoc();
// output data of each row
$idcategory = $category["id"];
$idposts = $posts["id"];
$idpostcat = $postscatID["category_id"];
if ($idpostcat == 5){
$TagID=10;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 7){
$TagID=12;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 13){
$TagID=17;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 14){
$TagID=18;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 15){
$TagID=19;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 16){
$TagID=20;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 27){
$TagID=29;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 28){
$TagID=30;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 30){
$TagID=32;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 34){
$TagID=35;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 35){
$TagID=36;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 37){
$TagID=38;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 38){
$TagID=39;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 49){
$TagID=47;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 50){
$TagID=48;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 52){
$TagID=50;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 53){
$TagID=51;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
if ($idpostcat == 55){
$TagID=46;
query($sql);
echo "<tr>";
echo "<td>". $idposts ."</td>";
echo "<td>". $TagID. "</td>";
echo "<td>". $idpostcat ."</td>";
echo "</tr>";
}
}
echo "</table>";} else {
echo "0 results";}
there is most likly a very easy way of doing this but its basically my first script.
I'm not getting any errors thats my prob, it gets to the while creates the table gets to the second if and then doesn nothing
If I remove the $sql
query the table works fine so some thing is wrong in my INSERT and I can't figure it out
Edit: error I'm getting is:
Undefined variable: idposts in /Applications/MAMP/htdocs/DEV/Technet-21/scripts/tags-categorys.php on line 50
Fatal error: Call to undefined function query() in /Applications/MAMP/htdocs/DEV/Technet-21/scripts/tags-categorys.php on line 69