PHP HTML output all Jacked up..

Discussion in 'PHP' started by advancedfuture, Jan 9, 2008.

  1. #1
    I posted this one PHPFREAKS but couldn't get an answers. I thought I would try here and see if someone can figure this out...

    My problem is I am trying to output data from my database and put a checkbox before the data.... now the data will come out just fine if i remove the followng line.


    
    echo "<input type=\"checkbox\" name=\"$u_msgid[$i]\" value=\"checkbox\" />";
    
    Code (markup):

    But with that line in the output comes out looking like this.

    [​IMG]

    The full code looks like this.

    
    <?php
    
    include 'session.php';
    include 'dbconnect.php';
    
    $query = "SELECT mailFrom FROM mail WHERE rcpt = '$username'";
    $results = mysql_query($query);
    $num = mysql_num_rows($results);
    
    $querySubj = "SELECT mailSubject FROM mail WHERE rcpt = '$username'";
    $resultsSubj = mysql_query($querySubj);
    $numSubj = mysql_num_rows($resultsSubj);
    
    $queryMsgID = "SELECT msgid FROM mail WHERE rcpt = '$username'";
    $resultsMsgID = mysql_query($queryMsgID);
    $numMsgID = mysql_num_rows($resultsMsgID);
    
    //echo '<form id="form1" name="form1" method="post" action="deleteMessage.php">';
    while($u_name=mysql_fetch_array($results) and $u_subj=mysql_fetch_array($resultsSubj) and $u_msgid=mysql_fetch_array($resultsMsgID))
    {
    	for($i = 0; $i < $num; $i++)
    	{
    	echo "<input type=\"checkbox\" name=\"$u_msgid[$i]\" value=\"checkbox\">";
    	echo "<a href =\"index.php?username=$u_name[$i]\">$u_name[$i]</a>";
    	echo "<a href=\"\">$u_subj[$i]</a>";
    	}
    	echo "<br />";
    }
    //echo '</form>';
    ?>
    
    Code (markup):
     
    advancedfuture, Jan 9, 2008 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    Its hard to say whats wrong with it if you don't tell us what is wrong with the output.
     
    papa_face, Jan 9, 2008 IP
  3. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I posted a screenshot of the output in the post... notice all the extra checkboxes it is generating after the subject line?
     
    advancedfuture, Jan 9, 2008 IP
  4. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The HTML output is coming out like this... it's adding way to many phantom checkboxes and blank URLs

    
    <form id="form1" name="form1" method="post" action="deleteMessage.php">
    <input type="checkbox" name="1" value="checkbox" />
    <a href ="index.php?username=jfrank">jfrank</a>
    <a href="">Test!</a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a><br />
    
    <input type="checkbox" name="2" value="checkbox" />
    <a href ="index.php?username=jfrank">jfrank</a>
    <a href="">Test!</a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a><br />
    
    <input type="checkbox" name="3" value="checkbox" />
    <a href ="index.php?username=jfrank">jfrank</a>
    <a href="">Test!</a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a>
    
    <input type="checkbox" name="" value="checkbox" />
    <a href ="index.php?username="></a>
    <a href=""></a><br />
    
    etc etc...
    
    Code (markup):
     
    advancedfuture, Jan 9, 2008 IP
  5. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #5
    First of all why do you do this with 3 queries when you could do it with one?
     
    Nikolas, Jan 9, 2008 IP
  6. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #6
    because i'm a newb at PHP and am unsure how to seperate the colums in the final output when spitting out the links.
     
    advancedfuture, Jan 9, 2008 IP
  7. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #7
    ok here is the right way to do this :

    
    <?php
    
    include 'session.php';
    include 'dbconnect.php';
    
    $query = "SELECT mailFrom, mailSubject,msgid  FROM mail WHERE rcpt = '$username'";
    $results = mysql_query($query);
    $num = mysql_num_rows($results);
    
    
    //echo '<form id="form1" name="form1" method="post" action="deleteMessage.php">';
    while($rec=mysql_fetch_array($results))
    {
    	echo "<input type=\"checkbox\" name=\"".$rec['msgid']."\" value=\"checkbox\">";
    	echo "<a href =\"index.php?username=".$rec['mailFrom']."\">".$rec['mailFrom']."</a>";
    	echo "<a href=\"\">".$rec['mailSubject']."</a>";
    	echo "<br />";
    }
    //echo '</form>';
    ?>
    
    PHP:
     
    Nikolas, Jan 9, 2008 IP
    advancedfuture likes this.
  8. advancedfuture

    advancedfuture Banned

    Messages:
    481
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #8
    THAT SOLVED IT!!!! THANKS! <3<3<3!!:D

     
    advancedfuture, Jan 9, 2008 IP
  9. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #9
    You are welcome :)
     
    Nikolas, Jan 9, 2008 IP