gerrydewar Posted April 2, 2006 Share Posted April 2, 2006 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"><?phpWhile 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? Quote Link to comment Share on other sites More sharing options...
Desdinova Posted April 2, 2006 Share Posted April 2, 2006 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 Link to comment Share on other sites More sharing options...
gerrydewar Posted April 2, 2006 Author Share Posted April 2, 2006 [!--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++;}//whileecho '</table>';?><input type="submit" name="submit"value="Submit Answers"></form>[/code] Quote Link to comment Share on other sites More sharing options...
Desdinova Posted April 2, 2006 Share Posted April 2, 2006 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 Link to comment Share on other sites More sharing options...
gerrydewar Posted April 2, 2006 Author Share Posted April 2, 2006 [!--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"><?phperror_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++;}//whileecho '</table>';$passedValue1 = serialize($ints);?><input type="hidden" name="ints" value="<? echo htmlentities($passedValue1)?>"/><input type="submit" name="submit"value="Submit Answers"></form></body>[/code] Quote Link to comment Share on other sites More sharing options...
Desdinova Posted April 2, 2006 Share Posted April 2, 2006 ok well it looks ok. could you paste the parsed HTML sourcecode? (you know, open it in the browser, right click, view source) Quote Link to comment Share on other sites More sharing options...
earl_dc10 Posted April 2, 2006 Share Posted April 2, 2006 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.