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.

Another line issue

Postby Epiales » Tue Sep 30, 2014 3:48 pm

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>&nbsp;&nbsp;'  $pid.' &nbsp;&nbsp;&nbsp; '$subject .' &nbsp;&nbsp;&nbsp;&nbsp; '$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
User avatar
Epiales
 
Posts: 1119
Joined: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times

Re: Another line issue

Postby Sim » Tue Sep 30, 2014 4:36 pm

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
Sim
 
Posts: 412
Joined: Sat Dec 26, 2009 12:37 pm
Location: Baltimore
Has thanked: 39 times
Been thanked: 13 times
Blog: View Blog (1)

Re: Another line issue

Postby KyleMassacre » Tue Sep 30, 2014 6:04 pm

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?
Skype: KyleMassacre
My NWE Modules
User avatar
KyleMassacre
 
Posts: 572
Joined: Wed Nov 27, 2013 7:42 am
Has thanked: 19 times
Been thanked: 36 times

Re: Another line issue

Postby Epiales » Tue Sep 30, 2014 6:25 pm

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
Epiales
 
Posts: 1119
Joined: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times

Re: Another line issue

Postby KyleMassacre » Tue Sep 30, 2014 10:42 pm

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
Skype: KyleMassacre
My NWE Modules
User avatar
KyleMassacre
 
Posts: 572
Joined: Wed Nov 27, 2013 7:42 am
Has thanked: 19 times
Been thanked: 36 times

Re: Another line issue

Postby Sim » Wed Oct 01, 2014 12:51 am

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
Sim
 
Posts: 412
Joined: Sat Dec 26, 2009 12:37 pm
Location: Baltimore
Has thanked: 39 times
Been thanked: 13 times
Blog: View Blog (1)

Re: Another line issue

Postby Epiales » Wed Oct 01, 2014 10:27 am

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'>&nbsp;&nbsp;NEW!&nbsp;&nbsp;</font></td>";
         }
         else
         
{
         echo "<td><left></td>";
         }
         if( strlen( $row['subject'] ) > 20 ) { $row['subject'] = left($row['subject'], 20) . "..."; } 


         echo 
"<td><left>$row[sender]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><left>$row[subject]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><left>$row[date]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times

Re: Another line issue

Postby Epiales » Wed Oct 01, 2014 2:39 pm

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

$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. '&nbsp;  &nbsp;  &nbsp; ';

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

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

    if ($pn != $lastPage) {
        $nextPage = $pn + 1;
        $paginationDisplay .=  '&nbsp;  <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!&nbsp;&nbsp;</font><left>$row[sender]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<left>$row[subject]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<left>$row[date]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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
Epiales
 
Posts: 1119
Joined: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times

Re: Another line issue

Postby MikuzA » Thu Oct 02, 2014 4:27 am

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.

viewtopic.php?p=66353#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
User avatar
MikuzA
 
Posts: 395
Joined: Thu Aug 08, 2013 3:57 am
Location: Helsinki, Finland
Has thanked: 0 time
Been thanked: 21 times


Return to Beginner Help and Support

Who is online

Users browsing this forum: No registered users and 1 guest

x