vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I want to simplify the following code. First I am reading in 6 values that do not change. Then I have 8 shifting values which are to be read in up to ten times. The value of $inx02 tells me how many times to read in these 8 values. Each time I read in the group of 8 values I need to increase $fx by 1 and read in the group again until $fx is equal to $inx02. The actual database has 14 fields. The first six values are repeated for every group of eight. What I need is some help in simplyfying the rest of this code so I can add 1 to $fx and lopp until my requirement is met. Do I have to connect to the database once for each entry of 14 fields or is there a way of storing values and connecting once to write everything. The maximum total of entries this can write in is 140. (ie 14 times the value of $inx02). This is the code so far... <?php $inx01=$_POST['fardvagonf']; $inx02=$_POST['vtcntf']; $inx03=$_POST['bestallf']; $inx04=$_POST['teleaf']; $inx05=$_POST['teleaf']; $inx06=$_POST['bestallmlf']; $fx = 1; $iny01=$_POST["fardvag$fx"]; $iny02=$_POST["fornamn$fx"]; $iny03=$_POST["efternamn$fx"]; $iny04=$_POST["postnum$fx"]; $iny05=$_POST["ort$fx"]; $iny06=$_POST["land$fx"]; $iny07=$_POST["ml$fx"]; $iny08=$_POST["genoms$fx"]; mysql_connect("localhost", "myusername", "mypassword") or die(mysql_error()); mysql_select_db("my_database") or die(mysql_error()); mysql_query("INSERT INTO `animals` VALUES ('$inx01', '$inx02', '$inx03', '$inx04', '$inx05', '$inx06', '$iny01', '$iny02', '$iny03', '$iny04', '$iny05', '$iny06', '$iny07', '$iny08', )"); Header("Location: http://www.mydomain.com/"); ?> The output to the database could be something like a, b, c, d, e, f, z, x, y, w, v, u, t, s a, b, c, d, e, f, o, z, g, h, i, m, v, w a, b, c, d, e, f, h, i, m, v, w, u, t, s a, b, c, d, e, f, z, x, y, w, v, u, t, s ie four entries with the first six fields in each entry identical. Any help greatly appreciated. Garry Jones Sweden |