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. "[email protected]" . $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???? Link to comment https://forums.phpfreaks.com/topic/230101-pass-array-to-mysql_fetch_row/ 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 />"; } Link to comment https://forums.phpfreaks.com/topic/230101-pass-array-to-mysql_fetch_row/#findComment-1185041 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 Link to comment https://forums.phpfreaks.com/topic/230101-pass-array-to-mysql_fetch_row/#findComment-1185053 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 Link to comment https://forums.phpfreaks.com/topic/230101-pass-array-to-mysql_fetch_row/#findComment-1185072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.