Jump to content

Whitespace and button positions


gerrydewar

Recommended Posts

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:

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

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.

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

<?php

While loop to display my questions

?>

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

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?
Link to comment
Share on other sites

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 :)
Link to comment
Share on other sites

[!--quoteo(post=360908:date=Apr 2 2006, 05:58 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 2 2006, 05:58 PM) [snapback]360908[/snapback][/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

[code]

<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>
[/code]
Link to comment
Share on other sites

[!--quoteo(post=360939:date=Apr 2 2006, 07:28 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 2 2006, 07:28 PM) [snapback]360939[/snapback][/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:

[code]
<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>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.