isimpledesign Posted March 9, 2011 Share Posted March 9, 2011 Hi I am looking to be able to pass an array to mysql_fetch_row() not sure where i am going wrong. works fine like this. mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); while ($row = mysql_fetch_array($new)) { echo $row['username'] . $DELIMITER . $row['firstname'] . $DELIMITER . $row['lastname'] . $DELIMITER . $row['password'] . $DELIMITER. "example@gmail.com" . $DELIMITER . "author"; echo "<br />"; } But really need too be able to do it this way. mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); echo "<pre>"; //print_r($row); echo "</pre>"; $sam = array('username','firstname','lastname'); while ($row = mysql_fetch_row($new)) { echo $row[$sam] . $DELIMITER; echo "<br />"; } So it will just loop through the array so i can keep adding to it by just adding an extra parameter to the array. Any Help Stuck???? Quote Link to comment Share on other sites More sharing options...
isimpledesign Posted March 9, 2011 Author Share Posted March 9, 2011 really need help any ideas on how i can change this while ($row = mysql_fetch_array($new)) { echo $row['username'] . $DELIMITER . $row['firstname'] . $DELIMITER . $row['lastname']; echo "<br />"; } to something like this $sam = array('username','firstname','lastname'); while ($row = mysql_fetch_array($new)) { echo $row[$sam] . $DELIMITER; echo "<br />"; } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 9, 2011 Share Posted March 9, 2011 Try something like this: <?php $sam = array('username','firstname','lastname'); while ($row = mysql_fetch_assoc($new)) { $tmp = array(); foreach ($sam as $v) { $tmp[] = $row[$v]; } echo implode($DELIMITER,$tmp) . "<br />\n"; } ?> Ken Quote Link to comment Share on other sites More sharing options...
isimpledesign Posted March 9, 2011 Author Share Posted March 9, 2011 Thankyou so much kenrbnsn saved my day 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.