Bendude14 Posted September 10, 2008 Share Posted September 10, 2008 I have this code and i am sure there must be away to make it smaller. The other problem im having i think may also be fixed at the same time. Let me sure you the code to explain further <?php while($dbarray = mysql_fetch_row($result)) { echo "<input type=\"text\" name=\"".$dbarray['1']."\" value=\"".$dbarray['1']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['2']."\" value=\"".$dbarray['2']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['3']."\" value=\"".$dbarray['3']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['4']."\" value=\"".$dbarray['4']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['5']."\" value=\"".$dbarray['5']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['6']."\" value=\"".$dbarray['6']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['7']."\" value=\"".$dbarray['7']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['8']."\" value=\"".$dbarray['8']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['9']."\" value=\"".$dbarray['9']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['10']."\" value=\"".$dbarray['10']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['11']."\" value=\"".$dbarray['11']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['12']."\" value=\"".$dbarray['12']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['13']."\" value=\"".$dbarray['13']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['14']."\" value=\"".$dbarray['14']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['15']."\" value=\"".$dbarray['15']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['16']."\" value=\"".$dbarray['16']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['17']."\" value=\"".$dbarray['17']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['18']."\" value=\"".$dbarray['18']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['19']."\" value=\"".$dbarray['19']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['20']."\" value=\"".$dbarray['20']."\" /><br />"; echo "<input type=\"text\" name=\"".$dbarray['21']."\" value=\"".$dbarray['21']."\" /><br />"; } ?> Is there a way i can just you var $i instead of having to hard code all the different rows i am retrieving? Also sometimes only 15 rows exists in the DB so then i get undefined variables. Is there a way to display only rows that exist? Thanks for the Help Quote Link to comment Share on other sites More sharing options...
tibberous Posted September 10, 2008 Share Posted September 10, 2008 LOL. while($dbarray = mysql_fetch_row($result)) for($t=1; $dbarray[$t]; $t++) echo "<input type=\"text\" name=\"".$dbarray[$t]."\" value=\"".$dbarray[$t]."\" /><br />"; Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted September 10, 2008 Author Share Posted September 10, 2008 Thanks thats exactly what i was looking for. it seems to be causing this error though now Notice: Undefined offset: 22 in C:\wamp\www\mqserver\admin\gallery_captions.php on line 51 Line 51 is the first line of the code you gave me. Thanks again Quote Link to comment Share on other sites More sharing options...
tibberous Posted September 10, 2008 Share Posted September 10, 2008 Does the code work? A notice isn't an error. Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted September 10, 2008 Author Share Posted September 10, 2008 yer the code works fine. Do you suggest i just suppress it out then? Quote Link to comment Share on other sites More sharing options...
tibberous Posted September 10, 2008 Share Posted September 10, 2008 What it does is go through the the subscripts until it hits one that it undefined, when then evaluates to false, when then breaks the loop. So, yes, you are using an undefined offset... that is the point, and also why I code with notices turned off. Add error_reporting(2). Or turn it off in WAMP... however you do that... Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted September 10, 2008 Author Share Posted September 10, 2008 Ok thanks for the help Ben Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 10, 2008 Share Posted September 10, 2008 Or you could make the code just a little more verbose and include some proper error checking as well as add clarity. [Notice the use of isset()] while($dbarray = mysql_fetch_row($result)) { for($t=1; isset($dbarray[$t]); $t++) { echo "<input type=\"text\" name=\"".$dbarray[$t]."\" value=\"".$dbarray[$t]."\" /><br />"; } } 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.