Jump to content


Photo

Whitespace and button positions


  • Please log in to reply
6 replies to this topic

#1 gerrydewar

gerrydewar
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 02 April 2006 - 04:36 PM

Hello again everyone.

I have two little problems with my code that i'm sure won't take a great deal of fixing. Firstly i want to display 2 variables in my browser with a gap in between them. The code i have at the moment is as follows:

echo '<tr><td align=\"left\"><b>'.$num , $questions.'</b></td></tr>..........

When i view the output in my browser i get something like '2Question' when i actually would like '2 Question'. I tried to use the command but i must have used it incorrectly as nothing happened.

The second problem concerns the position of a button when my code is viewed in my browser. I have a normal form that contains php code between the start and end form tags e.g.

<form name="testing"action="test1.php"method="POST">

<?php

While loop to display my questions

?>

<input type="submit" name="submit"value="Submit Answers">
</form>

When i run this code and view it in my browser my 'Submit Answers' button is positioned at the top of my page. I would like it to be positioned centrally at the bottom of my page after my while loop has finished displaying my last question. For some reason i'm finding this task rather difficult. I'm sure it will be fairly straight forward. Can someone please put me out of my misery?

#2 Desdinova

Desdinova
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 02 April 2006 - 04:58 PM

for the first:

' . $num . ' ' . $question . '

for the second,

I think your while loop is in a table, and your table is not properly closed when you echo the submit button (so your submit button probably shows up after a </tr> which positions it on top of the table).

there :)

#3 gerrydewar

gerrydewar
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 02 April 2006 - 05:52 PM

[!--quoteo(post=360908:date=Apr 2 2006, 05:58 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 2 2006, 05:58 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
for the first:

' . $num . ' ' . $question . '

for the second,

I think your while loop is in a table, and your table is not properly closed when you echo the submit button (so your submit button probably shows up after a </tr> which positions it on top of the table).

there :)
[/quote]


First one sorted thanks.

Second one:

My table start and end tags are outside the while loop. I do have a while loop inside my table though. The code looks like this


<form>
<?
echo '<table align="left" cellspacing="10" cellpadding="10">';
while ($row=mysql_fetch_assoc($result)){
echo '<tr><td align=\"left\"><b>'.$questions.'</b></td></tr>
<tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt1.'"/>'.$opt1.'</td></tr>
<tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt2.'"/>'.$opt2.'</td></tr>
<tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt3.'"/>'.$opt3.'</td></tr>
'."\n";
$num++;
}//while
echo '</table>';
?>
<input type="submit" name="submit"value="Submit Answers">
</form>


#4 Desdinova

Desdinova
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 02 April 2006 - 06:28 PM

ok, just for the fun of it, place a border in the table. does the table itself look ok? or a bit twisted?

and this is the exact code of what you are using?

#5 gerrydewar

gerrydewar
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 02 April 2006 - 06:43 PM

[!--quoteo(post=360939:date=Apr 2 2006, 07:28 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 2 2006, 07:28 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
ok, just for the fun of it, place a border in the table. does the table itself look ok? or a bit twisted?

and this is the exact code of what you are using?
[/quote]

Table looks fine. looks quite good with a border in it actually. Exact code is:

<body>
<form name="testing"action="test1.php"method="POST">

<?php

error_reporting(E_ALL);

//Connect to db.
require_once ('../mysql_connect.php');

//Select 10 random questions from database where the subject id is 1
$query = "SELECT question_id, question, answer, choice1, choice2, choice3 FROM questions WHERE subject_id = 1 ORDER BY RAND() LIMIT 10";
$result = @mysql_query ($query) or die('Problem with query:' . $query . '<br/>' . mysql_error()); //Run query
//echo 'Number of records found: '.mysql_num_rows($result)."<br/>\n";
$randomiseAnswer=rand(1,5);//used for randomising answer 
echo '<table align="left" cellspacing="10" cellpadding="10">';

$ints=array();
$num = 1;

while ($row=mysql_fetch_assoc($result)){

    
    echo '<tr><td align=\"left\"><b>'.$questions.'</b></td></tr>
    <tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt1.'"/>'.$opt1.'</td></tr>
    <tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt2.'"/>'.$opt2.'</td></tr>
    <tr><td align=\"left\"><input type="radio" name="choice['.$id.']"value="'.$opt3.'"/>'.$opt3.'</td></tr>
    '."\n";
    $num++;
}//while
echo '</table>';
$passedValue1 = serialize($ints);

?>
<input type="hidden" name="ints" value="<? echo htmlentities($passedValue1)?>"/>
<input type="submit" name="submit"value="Submit Answers">
</form>
</body>


#6 Desdinova

Desdinova
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 02 April 2006 - 06:54 PM

ok well it looks ok. could you paste the parsed HTML sourcecode? (you know, open it in the browser, right click, view source)

#7 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 02 April 2006 - 10:55 PM

does the table display where it should, only the submit button is messed up?? is the hidden value underneath the table, or is it above with the submit button?
got a problem? Google helps many of those in need




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users