Fabis94 Posted April 3, 2009 Share Posted April 3, 2009 Ok in the script i made variables like this: $row1collumn1, $row1collumn2 etc. the numbers after ROW and COLLUMN depend on the database entries. Anyways with $_POST they get sent to the action script (it is the same script though). Then i have this line: add2 = ' <td ' . $right_collumn['td'] . '>' . $add23 . '</td>'; And $add23 is: $add23 = '$row' . $c . 'collumn' . $d . ''; What i was trying to do is make that $add23 is the same as the rowXcollumnX and the FOR would change the values after ROW and COLLUMN but what it does is make the $add23 var be the string: '$rowXcollumnX' not be equal to a variable that has the name. It is hard to explain, but i think you got what i meant in the last sentance. Is there a way to make the $add2 var have the $rowXcollumnX variable between the <td> and </td> tags not just a string that says $rowXcollumnX Also with X i just meant the values that will be there. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2009 Share Posted April 3, 2009 You should use an array. Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 3, 2009 Author Share Posted April 3, 2009 What do you mean? How? Here's the whole script (there is still a PHP part with cookies and mysql_connect but it doesn't matter now): <form action="tableadd.php" method="post"> Select the table: <select name="whichtable"> <?php $select_tables = mysql_query("SELECT name,id FROM tables"); $num_rows_tables = mysql_num_rows($select_tables); while($assoc = mysql_fetch_assoc($select_tables)) { if ($assoc['id'] == 0) { echo '<option selected value="' . $assoc['name'] . '">' . $assoc['name'] . '</option>'; } else { echo '<option value="' . $assoc['name'] . '">' . $assoc['name'] . '</option>'; } } ?> </select> <input name="submit_select_table" type="submit" value="Select Table" /> </form><br /> <?php if (isset($_POST['whichtable'])) { $selectedtable = $_POST['whichtable']; $_SESSION['selectedtable'] = $selectedtable; echo '<br>'; $select_right_table = mysql_query("SELECT * FROM tables WHERE name='$selectedtable'") or die('Unable to select the TABLE collumn.'); $right_table = mysql_fetch_assoc($select_right_table) or die('Couldnt fetch assoc'); echo '<center>' . $right_table['table'] . '</center><br>'; $_SESSION['table'] = $right_table['table']; echo '<form action="tableadd.php" method="post">'; echo 'How much rows to add: <input name="hm_toadd" type="text" size="1" maxlength="1" /> '; echo '<input name="add_rows" type="submit" value="Submit" />'; echo '</form>'; } if (isset($_POST['add_rows'])) { $selectedtable = $_SESSION['selectedtable']; $right_table_show = $_SESSION['table']; echo '<center>' . $right_table_show . '</center><br><br><hr>'; $rc = mysql_query("SELECT * FROM tables WHERE name='$selectedtable'") or die('Cannot select $selectedtable'); $right_collumn = mysql_fetch_assoc($rc); $rightcoll = $right_collumn['collumns']; echo '<form action="tableadd.php" method="post">'; for ($a = 1; $a <= $_POST['hm_toadd']; $a++) { for ($b = 1; $b <= $right_collumn['collumns']; $b++) { echo 'Row ' . $a . ' Collumn ' . $b . ': <input name="row' . $a . 'collumn' . $b . '" type="text" /><br>'; } echo '<hr>'; } echo '<input name="add_rows_submit" type="submit" value="Add Rows" /></form>'; $_SESSION['hm_toadd'] = $_POST['hm_toadd']; } else { echo 'Select a table and enter how much rows do you want to add. If you want to add collums click HERE.'; } if (isset($_POST['add_rows_submit'])) { $rc = mysql_query("SELECT * FROM tables WHERE name='$selectedtable'") or die('Cannot select $selectedtable'); $right_collumn = mysql_fetch_assoc($rc); $hm_toadd = $_SESSION['hm_toadd']; $new = $hm_toadd * $right_collumn['collumns']; echo $new; for ($c = 1; $c <= $hm_toadd; $c++) { $add23 = '$row' . $c . 'collumn' . $d . ''; add1 = '<tr ' . $right_collumn['tr'] . '>'; for ($d = 1; $d <= $right_collumn['collumns']; $d++) { add2 = ' <td ' . $right_collumn['td'] . '>' . $add23 . '</td>'; } $add3 = '</tr>' $d++; } } ?> Also don't mind the variables repeating some times, this isn't the finished version of the script. Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 3, 2009 Author Share Posted April 3, 2009 Hello? What should i do with arrays! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 3, 2009 Share Posted April 3, 2009 Instead of having a load of variables: $name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8, $name9, $name10 You can make an array: $name=array('a','b','c','d','e','f','g','h','i','j'); That way you can access them with a number rather than typing the entire variable name in each time (makes it a LOT easer!) echo $name[2]; Return c Array indexes always start at 0 so 0=a, 1=b, 2=c etc. Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 3, 2009 Author Share Posted April 3, 2009 Well the rowXcollumX is the NAME of the input field (For example, first input field has name="row1collumn1" the second one has name="row1collumn2"). How do i add all the values to an array from the $_POST? (Like the first input field will be $_POST['now1collumn1']) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2009 Share Posted April 3, 2009 You should use an array for your form fields as well - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 3, 2009 Author Share Posted April 3, 2009 Oh i didn't know you could do that. Anyways i have a Database cell that has </table> as the last word/string in it. How do i make MYSQL remove it (so i can add my strings i got from $_POST and then put the </table> back again)? Quote Link to comment Share on other sites More sharing options...
Fabis94 Posted April 3, 2009 Author Share Posted April 3, 2009 Oh and i don't want to get the cell in a var and then remove the end with PHP, but just do it straight with a query. 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.