dalcacio2007 Posted March 14, 2008 Share Posted March 14, 2008 hello everyone i usually try to google for the answears and learn on my own but right now i'm really stuck... What i need is to query a database and echo the value of every field in the row and then move to the next row. now each row has way too many field. i thought i could avoid specifying $row['field'] by doing a foreach loop since $row is an array... but apparently something went wrong... the values are coming out repeated the output for this is --(row1)-- value1 value1 value2 value2 ... and so on --(row2)-- value1 value1 value2 value2 ... and so on any idea what could be going wrong? here's my code Thanks for ur help <?php $con = mysql_connect("(ipaddress)","(user)","(pass)"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("(database)", $con); $msqlq = "SELECT * FROM (table)"; $result = mysql_query($msqlq) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { foreach($row as $field) { echo $field.'<br>';//the <br> is just for debuggin purposes } } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/96188-need-some-help-with-php-and-mysql/ Share on other sites More sharing options...
dalcacio2007 Posted March 14, 2008 Author Share Posted March 14, 2008 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/96188-need-some-help-with-php-and-mysql/#findComment-492410 Share on other sites More sharing options...
Psycho Posted March 14, 2008 Share Posted March 14, 2008 From the manual: mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both The default is both. So all elements are available by their column name and a numerical index. Either add the appropriate parameter to mysql_fetch_array() to get only one set of data or use mysql_fetch_assoc() or mysql_fetch_row(). EDIT: You posted your "any ideas?" comment while I was preparing this reply. If I had seen it before I wrote the above I would not have even bothered with a response. This is a forum where people voluntarily provide help. Waiting 11 minutes before asking "any ideas" is presumptuous to say the least. Quote Link to comment https://forums.phpfreaks.com/topic/96188-need-some-help-with-php-and-mysql/#findComment-492413 Share on other sites More sharing options...
dalcacio2007 Posted March 14, 2008 Author Share Posted March 14, 2008 sorry won't happen again thanks for the help, i really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/96188-need-some-help-with-php-and-mysql/#findComment-492418 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.