jr8rdt Posted June 1, 2007 Share Posted June 1, 2007 do you know why when I run this code below I get several blank lines before the first record is printed? I strongly suspect that this has something to do with while($row = mysql_fetch_array($result, MYSQL_ASSOC)) but can't figure it out. is there an alternative? help ---------- include 'db_connect.php'; $query = "SELECT * FROM server ORDER BY server_id"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id1 = "{$row['server_id']}"; echo "<tr>"; echo "<form name='myform' action='modify.php' method='post'>"; echo " <td><a href='modify.php?id1=$id1'> {$row['server_id']}</a></td>"; echo "</form>"; echo "<td>{$row['server_hostname']} </td>"; echo "<td>{$row['server_ip']} </td>"; echo "<td>{$row['server_status']} </td>"; echo "<td>{$row['server_os']} </td>"; echo "<td>{$row['server_hw']} </td>"; echo "<td>{$row['server_sw']} </td>"; echo "<td>{$row['server_user']} </td>"; echo "<td>{$row['server_date']} </td>"; echo "<td>{$row['server_desc']} </td>"; echo "</tr><br>"; } Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/ Share on other sites More sharing options...
AndyB Posted June 2, 2007 Share Posted June 2, 2007 echo "<form name='myform' action='modify.php' method='post'>"; echo " <td><a href='modify.php?id1=$id1'> {$row['server_id']}[/url]</td>"; echo "</form>"; That doesn't make much sense. Remove the opening and closing form statements completely - they're doing nothing useful. As to the blank lines, that sounds like empty rows in your database. Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-266620 Share on other sites More sharing options...
jr8rdt Posted June 4, 2007 Author Share Posted June 4, 2007 I don't have blank/empty rows in my db. the weird thing is the more I add records the more it has blank lines. I know it's something wrong with the while statement. just can't figure it out. Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267592 Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 Use [ code ] tags, they help everyone out. <?php include 'db_connect.php'; $query = "SELECT * FROM server ORDER BY server_id"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<pre>',print_r($row),'</pre><br />'; continue; $id1 = "{$row['server_id']}"; echo "<tr>"; echo "<form name='myform' action='modify.php' method='post'>"; echo " <td><a href='modify.php?id1=$id1'> {$row['server_id']}[/url]</td>"; echo "</form>"; echo "<td>{$row['server_hostname']} </td>"; echo "<td>{$row['server_ip']} </td>"; echo "<td>{$row['server_status']} </td>"; echo "<td>{$row['server_os']} </td>"; echo "<td>{$row['server_hw']} </td>"; echo "<td>{$row['server_sw']} </td>"; echo "<td>{$row['server_user']} </td>"; echo "<td>{$row['server_date']} </td>"; echo "<td>{$row['server_desc']} </td>"; echo "</tr> "; } ?> try the above and see what is being printed out in your $row array. Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267595 Share on other sites More sharing options...
chrisuk Posted June 4, 2007 Share Posted June 4, 2007 Do you not need to define $row and then extract it? eg: <?php $query = "SELECT * FROM server ORDER BY server_id"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); extract ($row); this may not actually be necessary but that is how I have done it in the past Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267596 Share on other sites More sharing options...
per1os Posted June 4, 2007 Share Posted June 4, 2007 Do you not need to define $row and then extract it? eg: <?php $query = "SELECT * FROM server ORDER BY server_id"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); extract ($row); this may not actually be necessary but that is how I have done it in the past No with the code he has that is not necessary and is probably not a good idea. The extract function is nice sometimes but yea, if there is more than 1 row in that database the code you just posted would not go any good as that would only get the first row. $row is returned as an array as such the variables are accessed by the name of the column which is the index. The real question is, is he calling the column names correctly. Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267598 Share on other sites More sharing options...
chrisuk Posted June 4, 2007 Share Posted June 4, 2007 Do you not need to define $row and then extract it? eg: <?php $query = "SELECT * FROM server ORDER BY server_id"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); extract ($row); this may not actually be necessary but that is how I have done it in the past No with the code he has that is not necessary and is probably not a good idea. The extract function is nice sometimes but yea, if there is more than 1 row in that database the code you just posted would not go any good as that would only get the first row. $row is returned as an array as such the variables are accessed by the name of the column which is the index. The real question is, is he calling the column names correctly. Thanks for that! I have actually experienced some problems in the past...this is probably why....mental note made! Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267600 Share on other sites More sharing options...
jr8rdt Posted June 4, 2007 Author Share Posted June 4, 2007 This is the output. I miss what you're trying to do here. Array ( [server_id] => 1 [server_hostname] => dadaadam [server_ip] => 121.21.233.11 [server_status] => Active [server_os] => Windows Server 2003 [server_hw] => Dual-Core AMD Opteron Processor 8218 [server_sw] => S20 [server_user] => Junior [server_date] => 2007-06-01 13:38:29 [server_desc] => Test ) 1 Array ( [server_id] => 2 [server_hostname] => gdf3321 [server_ip] => 23.23.42.32 [server_status] => Active [server_os] => Windows Server 2003 [server_hw] => Dual-Core AMD Opteron Processor 8218 [server_sw] => BS1 [server_user] => Junior [server_date] => 2007-06-01 14:11:05 [server_desc] => ) 1 Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267926 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 Have you removed that redundant form AndyB spoke of? Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-267933 Share on other sites More sharing options...
jr8rdt Posted June 5, 2007 Author Share Posted June 5, 2007 yes I did. but the extra empty lines are still there. Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-268736 Share on other sites More sharing options...
kenrbnsn Posted June 5, 2007 Share Posted June 5, 2007 Please post the result of a "show source" in the browser of your choice. I have seen extra blank lines when a "<br>" tag is outside the confines of "<td></td>" tags. Ken Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-268809 Share on other sites More sharing options...
jr8rdt Posted June 7, 2007 Author Share Posted June 7, 2007 That's it !! "br" it is . It is good now. tx Link to comment https://forums.phpfreaks.com/topic/53908-whilerow-mysql_fetch_arrayresult-mysql_assoc/#findComment-269976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.