The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Problem with correct placing of tables posted with php - sql, Might be a styling issue
sanoj96
post Mar 12 2017, 01:28 PM
Post #1


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



Hello,

So i have been messing around a bit now with one of my websites, and have ran into a problem i cant see to find out.
So i am asking for some help..


So when i try to post a table from php with information from sql it places at the wrong area..


This are the following files are in use in this action.

index.php

CODE

<?php
//create_cat.php
include 'connect.php';
include 'header.php';

$sql = "SELECT
            categories.cat_id,
            categories.cat_name,
            categories.cat_description,
            COUNT(topics.topic_id) AS topics
        FROM
            categories
        LEFT JOIN
            topics
        ON
            topics.topic_id = categories.cat_id
        GROUP BY
            categories.cat_name, categories.cat_description, categories.cat_id";

$result = mysql_query($sql);

if(!$result)
{
    echo 'The categories could not be displayed, please try again later.';
}
else
{
    if(mysql_num_rows($result) == 0)
    {
        echo 'No categories defined yet.';
    }
    else
    {
        //prepare the table
        echo '<table class="table table-striped">
              <tr>
                <th>Category</th>
                <th>Last topic</th>
              </tr>';    
            
        while($row = mysql_fetch_assoc($result))
        {                
            echo '<tr>';
                echo '<td class="leftpart">';
                    echo '<h3><a href="category.php?id=' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></h3>' . $row['cat_description'];
                echo '</td>';
                echo '<td class="rightpart">';
                
                //fetch last topic for each cat
                    $topicsql = "SELECT
                                    topic_id,
                                    topic_subject,
                                    topic_date,
                                    topic_cat
                                FROM
                                    topics
                                WHERE
                                    topic_cat = " . $row['cat_id'] . "
                                ORDER BY
                                    topic_date
                                DESC
                                LIMIT
                                    1";
                                
                    $topicsresult = mysql_query($topicsql);
                
                    if(!$topicsresult)
                    {
                        echo 'Last topic could not be displayed.';
                    }
                    else
                    {
                        if(mysql_num_rows($topicsresult) == 0)
                        {
                            echo 'no topics';
                        }
                        else
                        {
                            while($topicrow = mysql_fetch_assoc($topicsresult))
                            echo '<a href="topic.php?id=' . $topicrow['topic_id'] . '">' . $topicrow['topic_subject'] . '</a> at ' . date('d-m-Y', strtotime($topicrow['topic_date']));
                        }
                    }
                echo '</td>';
            echo '</tr>';
        }
    }
}
?>

<?php
include 'footer.php';
?>


The problem is that everything that is a table is under the footer (only on index.php & if you click on a topic / Category. but if i click on the post it is above the footer.)


Link to site:
http://solitudegaming.com/forum

Hope anyone can help me with this issue.

Thanks.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 12 2017, 03:02 PM
Post #2


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Your posted code doesn't show it but there is an extra '<body>' tag placed before the <table>. Also, I see you're using mysql_* commands in your code. mysql_* commands are deprecated and removed from PHP v7. You should use prepared statements with mysqli_* commands or use PDO.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 03:31 PM
Post #3


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



Oh, thanks.

I know it's the part with mysql_* and PDO. It is running on an kind of old system atm. Working on a new script for it atm, but first i will fix the themeing and so on smile.gif

How can i fix the issue about the "invisible" <body> tag?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 12 2017, 03:43 PM
Post #4


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The extra <body> tag may not be in your PHP code at all. It might be in the actual HTML file that runs the PHP script. Check there first.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 03:55 PM
Post #5


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



Yea, figured that out tongue.gif found one extra body tag inside the header.php file. removed the one that is not needed, and saved the file. Same error..
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 03:57 PM
Post #6


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



This page works like it should: http://solitudegaming.com/forum/topic.php?id=3
But the rest dosent.

Checking the code on both of them too see if i am missing a div or something
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 04:03 PM
Post #7


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



This might also have been moved more over to a css category ..
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 04:14 PM
Post #8


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



Tried to past the raw html from the footer.php file into the index.php file (at the bottom) still same issue. This is now a styling problem (or have always been one.)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 12 2017, 04:16 PM
Post #9


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I just checked http://solitudegaming.com/forum again and it seems to be working correctly. What problem do you still have?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 05:16 PM
Post #10


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



i still see the fotter above the table.. do you see the same?
IPB Image
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 12 2017, 05:18 PM
Post #11


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



It should be looking like this:

IPB Image

idk why that page work, but not the other pages..

They are basicly the same but gather info from different sql bases..
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 12 2017, 07:40 PM
Post #12


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



The reason is that you forgot to close the table. After you echo the last </tr> you then need to echo </table> also.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
sanoj96
post Mar 13 2017, 02:26 PM
Post #13


Member
***

Group: Members
Posts: 95
Joined: 18-September 12
Member No.: 17,803



Thank you, i should have found that my self rolleyes.gif

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 13 2017, 03:50 PM
Post #14


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Sometimes a different set of eyes is needed. Glad it helped.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Mar 13 2017, 06:18 PM
Post #15


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 17,646
Joined: 9-August 06
Member No.: 6



Or a validator. happy.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 13 2017, 07:38 PM
Post #16


This is My Life
*******

Group: Members
Posts: 1,413
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(pandy @ Mar 13 2017, 06:18 PM) *

Or a validator. happy.gif
Or even, 'View source', on the page generated by the PHP code. smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 21st August 2017 - 10:21 PM