Another line issue

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

Another line issue

Post by Epiales »

I am working on my inbox script. When I call the information from the database, the read button is on a seperate line. Why? I have dug for hours trying to find out why. Below is some basic code if someone can look to see if there is an issue with it. If you need more code, please let me know. Thank you for looking at it.

Code: Select all

$outputList .= '<b>' . '<font color="red"> NEW!</font>  '  . $pid.'     '. $subject .'      '. $date . '<form method="post" align="right" action="messages.php"><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></b><hr />'; 

Code: Select all

      <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>
Nothing fancy, but a work in progress!

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

Re: Another line issue

Post by Sim »

I think its because the <form element always starts off on a new line. I may be wrong though.
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Another line issue

Post by KyleMassacre »

Sim wrote:I think its because the <form element always starts off on a new line. I may be wrong though.
I think you are right. Why dont you just use a link to read the message?
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Another line issue

Post by Epiales »

KyleMassacre wrote:
Sim wrote:I think its because the <form element always starts off on a new line. I may be wrong though.
I think you are right. Why dont you just use a link to read the message?
Even with just a link, it's still going to have the form, because I'll be passing information to the same php page. I don't personally believe it's because it's forced to start a new line. There has to be a fix for it. I hope so anyway LMAO... Thank you both for u're input. I appreciate the people that try and help me :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

Re: Another line issue

Post by KyleMassacre »

Code: Select all

echo "<a href='messages.php?read=true&readmessage=1&randid=".$row["randid"]."&date=".$row["date"]."'>Read</a>";
Same effect just not using a form, and change all your $_POSTs to $_GETs. Remember, pretty much what you can do with a form using post, you can achieve using get. What it seems like you are trying to do based on the snippet you provided, you don't need a form because your not submitting user input. And you honestly wouldn't need all that data in the url anyway, you can just pass some sort of unique identifier in the url, grab in messages.php and extract the data based on that
Sim
Posts: 412
Joined: Sat Dec 26, 2009 5:37 pm

Re: Another line issue

Post by Sim »

Don't forget to verify that the MESSAGE actually belongs to the USER or anyone can read EVERY message =)
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Another line issue

Post by Epiales »

Okay, after many hours of going completely mad, I have it figured out. Below works well and puts everything on one line. I ended up using tables:

Code: Select all

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

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

$messageinfo = "SELECT * FROM messages where pid='$user_username' ORDER BY date DESC"; 
$user_query = mysqli_query($db_conx, $messageinfo);
$numrows = mysqli_num_rows($user_query);

echo "<table>";

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

      if($row['readm'] == 1)
           {
         echo "<tr><td><left><font color = 'red'>  NEW!  </font></td>";
         }
         else
         {
         echo "<td><left></td>";
         }
         if( strlen( $row['subject'] ) > 20 ) { $row['subject'] = left($row['subject'], 20) . "..."; } 


         echo "<td><left>$row[sender]          </td><td><left>$row[subject]        </td><td><left>$row[date]      </td><td><left><form method='post' action='messages.php'><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></td></tr>";
           
           }
      print "</table>";
      print "</td></tr></table>";    
               echo "</small>";    
Image

Thank you all for u're ideas and suggestions :)
Nothing fancy, but a work in progress!

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

Re: Another line issue

Post by Epiales »

Okay, although I did get the button to go in one line... The pagination has messed it up again LMAO! Now it's back on two lines and I can't seem to find the error. Here is all the code for the inbox display of messages if anyone has time to wade through and find out why the READ is moved down to another line instead of on same line with the rest.

Code: Select all

<body style=" font-family:Arial;">
    <div style="width: 700px; margin: 0 auto; padding: 120px 0 40px;">
        <ul class="tabs" data-persist="true">
            <li><a href="#view1">Inbox</a></li>
            <li><a href="#view2">Send Messages</a></li>
            <li><a href="#view3">Read Messages</a></li>
        </ul>
        <div class="tabcontents">
            <div id="view1">
                <b>---------------------- Message Inbox ---------------------</b>
               <p>
           
<?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 = '1'>";


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

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

} else { 
    $pn = 1;
} 

$itemsPerPage = 10; 

$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 ASC $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'], 10) . "...";     
    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='messages.php'><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
         {

        }     
        
    }
}

?>

   <div style="margin-left:64px; margin-right:64px;">

   </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

           }
      print "</table>";
      print "</td></tr></table>";    
               echo "</small>";    
?>
This is what it currently looks like, and I have the pagination working fine; it just has the stupid read button on another line :evil: :evil:

Image
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: Another line issue

Post by MikuzA »

Wink, it's the <form>, causes next-lines.. change your button to have a name and a value, and obtain the info using $_POST.
HAve the <form> outside the loop/data.

http://indie-resource.com/forums/viewto ... 353#p66353

See my example of the layout from another thread of yours ^_<
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
Post Reply

Return to “Beginner Help and Support”