j3rmain3 Posted November 10, 2006 Share Posted November 10, 2006 I want to display information from several dropdown menus in a table and it would be too time consuming if i was to type in the name i have given to every option. So i have placed this:echo "<td><p align=center><font face=Verdana size=-1>[b]".$row[filename]tech"[/b]</center></td>";echo "<td><p align=center><font face=Verdana size=-1>[b]".$row[filename]fin"[/b]</center></td>";echo "<td><p align=center><font face=Verdana size=-1>[b]".$row[filename]doc"[/b]</center></td>";The names in the dropdown menu end in either TECH, FIN or DOC.This is how the data in the dropdown menu has been setup:<option value=1 name=$row[filename]tech>This works fine because the name of the option is stored as 'segatech' like it is supposed to. But this only works becasue i have the whole thing within quotes.I have placed the table like this so the data from the dropdown menu will appear in the cell. But i keep on getting an error which says i cannot have the $row[filename][b]tech[/b] bit. Is there anyway i can work around this. ???Thanks,J3rmain3 Quote Link to comment Share on other sites More sharing options...
blear Posted November 10, 2006 Share Posted November 10, 2006 The array cant be concatinated into HTML output that way.[code]...size=-1>".$row[filename]tech"</cen.... [/code]should become[code] size=-1>" . $row[filename] . "tech</cen.... [/code] Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 10, 2006 Author Share Posted November 10, 2006 One more problem im having, i have created a form and a table which i want to display the data in. To move the data from the form to the table, i know that i have to place something like this in at the top:$variable1 = $_POST['variable1'];$variable2 = $_POST['variable2'];$variable3 = $_POST['variable3'];Is there anyway i can turn this into a loop so that variable4 will appear next without having to do it manually.Thanks,J3rmain3.N.B. I have asked this question 3 times b4 and nobody as helped me so please (thats me pleading) somebody help me. Quote Link to comment Share on other sites More sharing options...
Zane Posted November 10, 2006 Share Posted November 10, 2006 extract($_POST); Quote Link to comment Share on other sites More sharing options...
blear Posted November 10, 2006 Share Posted November 10, 2006 j3r-No, you cant assign $variable4, $variable5, $variable6, etc. inside a loop. That has to be done with an array. Instead of $variable4, you have $variable[4]. You will need to read up on arrays and their usage. Quote Link to comment Share on other sites More sharing options...
Monkeymatt Posted November 10, 2006 Share Posted November 10, 2006 You [b]can[/b] assign $variable4, $variable5, $variable5, etc inside a loop:[code]$num=5; // number of variable(num) to extractfor ($i=1;$i<=$num;$i++) { $go="variable".$i; $$go=$_POST[$go];}[/code]http://us2.php.net/manual/en/language.variables.variable.phpMonkeymatt Quote Link to comment Share on other sites More sharing options...
Zane Posted November 10, 2006 Share Posted November 10, 2006 yeah your right, he can do thatbut look at his keys for POST$variable1 = $_POST['variable1'];$variable2 = $_POST['variable2'];$variable3 = $_POST['variable3'];they're just the same as the name of the variables he wantsso he'd be just as well off using extract.I don't know why you don't just use the POST vars themselves, directly$variabel1 = $_POST['variable1'];echo $variable1;Does the same thing asecho $_POST['variable1'];nothing really different at all. Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 13, 2006 Author Share Posted November 13, 2006 [code]$num=5; // number of variable(num) to extractfor ($i=1;$i<=$num;$i++) { $go="variable".$i; $$go=$_POST[$go];}[/code]I have used the coding which MonkeyMat has explained. I looked up extract but did not understand it very well.I have been able to use the foundations of the coding above and applied it to my table, but i am confused about something. To see if the coding comes out correct i used [b]echo[/b] >>>>> This is how i printed out the coding,[code]$x = "$";echo "$x$go = ${$go}";[/code]the output to this is $variable1 =But the $_POST[variable1] bit doesnt appear. I understand that it will not appear because its a reserved function (or something like that ) but how do i get this to be recognised by the server so that i can send information from the form to the table.ThanksJ3rmain3 Quote Link to comment Share on other sites More sharing options...
j3rmain3 Posted November 15, 2006 Author Share Posted November 15, 2006 I am trying to display numbers which have been sent from a form but i get the error message:Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\Apache\Apache2\PHPFiles\brainstorm\btable.php on line 42This is the code:while ($row=mysql_fetch_assoc($result)){$num = $row;for ($i=1;$i<=$row;$i++) { $post = $row['filename']."tech"; $$post = $_POST[$post];}[b]42:[/b] echo "<td><font face=Verdana size=-1>".${$post}"</td>";Can anyone see what is wrong IN LINE 42? Isn't that the way i display something using variable variableThanksJ3RMAIN3 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.