YAY Lining Things Up!!! [RESOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

YAY Lining Things Up!!! [RESOLVED]

Post by Epiales »

I finally have the messaging system done. It sends the messages, displays, and deletes the messages. It alerts player if it's a new message, and it's paginated. But it looks like total garbage b/c nothing is lined up :lol: :lol: :lol:

I've tried using <td></td> and spaces and everything to get it lined up, but all it dies is mess up the outlay of the while loop display. Any help would be greatly appreciated.

Code: Select all

<?php
$bypass = 0;
if($bypass != 1)

{
if(isset($_GET['messages']) || isset($_POST['messages'])) 
{
$bypass = 1;

$sql = "SELECT * FROM messages WHERE pid='$user_username' ORDER BY date DESC"; 
$user_query = mysqli_query($db_conx, $sql);
$nr = mysqli_num_rows($user_query);

echo "<left>";
echo "<table border = '0' width = '100%' cellspacing = '5'>";


echo "<td valign = 'top' width = '100%'>";

if (isset($_GET['pn'])) {  
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']);  

} else { 
    $pn = 1;
} 

$itemsPerPage = 5; 

$lastPage = ceil($nr / $itemsPerPage);

if ($pn < 1) {  
    $pn = 1;  
} else if ($pn > $lastPage) {  
    $pn = $lastPage;  
} 

$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a>  ';
} else if ($pn == $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub2 . '">' . $sub2 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add2 . '">' . $add2 . '</a>  ';
} else if ($pn > 1 && $pn < $lastPage) {
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $sub1 . '">' . $sub1 . '</a>  ';
    $centerPages .= '  <span class="pagNumActive">' . $pn . '</span>  ';
    $centerPages .= '  <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $add1 . '">' . $add1 . '</a>  ';
}

$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; 

$sql = "SELECT * FROM messages WHERE pid='$user_username' ORDER BY date DESC, readm=1 DESC $limit"; 
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);

$paginationDisplay = "";  

if ($lastPage != "1"){

    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '        ';

    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $previous . '"> Back</a> ';
    } 

    $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';

    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '   <a href="' . $_SERVER['PHP_SELF'] . '?messages=1&pn=' . $nextPage . '"> Next</a> ';
    } 
}

$outputList = '';

while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {

    $row['subject'] = left($row['subject'], 20) . "...";     
    if($row['readm'] == 1) {

    $outputList .= "<left><font color = 'red'>NEW!   </font><left>$row[sender]          <left>$row[subject]                  <left>$row[date]      <right><form method='post' action='mafiawarskingdom.php?messages=1'><input type='submit' value='Read'>
       <input type='hidden' name='readmessage' value='1'>
       <input type='hidden' name='randid' value='$row[randid]'>
       <input type='hidden' name='date' value='$row[date]'>
        </form>";
         
}
         else
         {
    $outputList .= "            <left></font><left>$row[sender]           <left>$row[subject]                <left>$row[date]      <right><form method='post' action='mafiawarskingdom.php?messages=1'><input type='submit' value='Read'>
       <input type='hidden' name='readmessage' value='1'>
       <input type='hidden' name='randid' value='$row[randid]'>
       <input type='hidden' name='date' value='$row[date]'>
        </form>";

        }     
        
    }
}

?>
Code that displays output below. Now if I remove what tables I have echoed, it will completely mess up the form and throw everything on different rows or such. So instead of changing the format I have, I need to just be able to add to it in order to line everything up IF I can. Thank you again, and sorry for all the posts. Here is what it currently looks like:

Image

Code: Select all

   </div> 
      <div style="padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
      <div align="left"><?php echo "$outputList"; ?></div>
      <div style="padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>

<?php

}           
      echo "</table>";
      echo "</td></tr></table>";    
      echo "</small>";    
?>
Last edited by Epiales on Thu Oct 02, 2014 9:17 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Sim
Posts: 412
Joined: Sat Dec 26, 2009 5:37 pm

Re: YAY Lining Things Up!!!

Post by Sim »

Im not much of an HTML expert BUT

Code: Select all

"            <left></font><left>$row[sender]           <left>$row[subject]                <left>$row[date]      
BADDDDDDDDDDDDDDDDDDDDDDD.. I would just use some tables and a center tag?
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: YAY Lining Things Up!!!

Post by MikuzA »

Yes, that   repeating is kinda awful :D
When developing, just put them in a table for starters, and then when you feel fancy and your code is ready.. Start digging into Div's if necessary. But table combined with css is a best approach when doing similiar row loop when outputting data.

Code: Select all

<form method='post' action='mafiawarskingdom.php?messages=1'> // this outside of the table or inside the table right after <table>, but out of the loop.
<table> //put this outside the 'loop'

<tr> //starting a new row

<td width=100>  //just some width for the first column to have the 'NEW' in sync if there's not 'NEW'-flash.
<font color="RED">NEW!</font> // remove this from the other condition, ofc.
</td> // ending first column.

<td> // starting sender column.
$row['sender'] // inserting sender_data
</td> // ending column..

<td> // starting subject column.
$row['subject'] // inserting subject_data
</td> // ending column..

<td> //starting received date-column
$row['date'] //inserting date-data
</td> //ending column

<td> // starting 'READ'-button column
<input type='submit' name='Read' value='$mail_id'> // perhaps change this to something like this, so you don't have to recreate your form for every e-mail. And move the <form> before or after the <table>-outside the loop.
</td> // ending the column

</tr> // ending the row

//while-loop ends here.

</table> // end the table.

Hope this helps, this is really a 'hand-held' guidance through, so pick the stuff you need :) (have not tested, there might be typos)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: YAY Lining Things Up!!!

Post by Epiales »

Sim wrote:Im not much of an HTML expert BUT

Code: Select all

"            <left></font><left>$row[sender]           <left>$row[subject]                <left>$row[date]      
BADDDDDDDDDDDDDDDDDDDDDDD.. I would just use some tables and a center tag?
LMAO! I know I know I know :mrgreen: :mrgreen: :mrgreen: :oops: :oops: :oops:

But I have tried doing it with tables and it just messes it all up worse lol. But yeah, I agree, they are really bad.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: YAY Lining Things Up!!!

Post by Epiales »

MikuzA wrote:Yes, that   repeating is kinda awful :D
When developing, just put them in a table for starters, and then when you feel fancy and your code is ready.. Start digging into Div's if necessary. But table combined with css is a best approach when doing similiar row loop when outputting data.

Code: Select all

<form method='post' action='mafiawarskingdom.php?messages=1'> // this outside of the table or inside the table right after <table>, but out of the loop.
<table> //put this outside the 'loop'

<tr> //starting a new row

<td width=100>  //just some width for the first column to have the 'NEW' in sync if there's not 'NEW'-flash.
<font color="RED">NEW!</font> // remove this from the other condition, ofc.
</td> // ending first column.

<td> // starting sender column.
$row['sender'] // inserting sender_data
</td> // ending column..

<td> // starting subject column.
$row['subject'] // inserting subject_data
</td> // ending column..

<td> //starting received date-column
$row['date'] //inserting date-data
</td> //ending column

<td> // starting 'READ'-button column
<input type='submit' name='Read' value='$mail_id'> // perhaps change this to something like this, so you don't have to recreate your form for every e-mail. And move the <form> before or after the <table>-outside the loop.
</td> // ending the column

</tr> // ending the row

//while-loop ends here.

</table> // end the table.

Hope this helps, this is really a 'hand-held' guidance through, so pick the stuff you need :) (have not tested, there might be typos)
Thank m8! I will try again lol. If at first you don't succeed, try, try again. I will update trying to use u're formula. Thank you!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: YAY Lining Things Up!!!

Post by Epiales »

Thanks everyone! I think I have it finished now

Image
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”