function Build_Array($mysql_result_pointer) { if(mysql_num_rows($mysql_result_pointer)) { $res[] = mysql_field_name($mysql_result_pointer); while($row = mysql_fetch_array($mysql_result_pointer)) { $res[] = row; } } return($res); }
Jim Lucas bend.com ----- Original Message ----- From: "Justin French" <[EMAIL PROTECTED]> To: "php" <[EMAIL PROTECTED]> Sent: Monday, January 21, 2002 4:12 PM Subject: [PHP] smarter code (mySQL arrays) > Hi all, > > I've got into the habbit of pulling data out of a table something like this: > > > $sql = "SELECT * FROM cd_review WHERE publish='yes' ORDER BY id DESC > LIMIT 3"; > $sql_result = mysql_query($sql); > print mysql_error(); > while ($sql_myrow = mysql_fetch_array($sql_result)) > { > // pull out the data > $id = $sql_myrow["id"]; > $date = $sql_myrow["date"]; > $user_id = $sql_myrow["user_id"]; > $artist = $sql_myrow["artist"]; > $title = $sql_myrow["title"]; > // edited out about 10 colums for clarity > } > > Now, I reckon there must be a way of automating the task of making the > $title var out of $sql_myrow["title"] etc etc for starters, which would > really help on tables with lots of columns. > > Then, it'd be great if I could automate this further to automaticaly to > a stripslashes() on each var, then possibly nl2br() etc. > > > In psuedo-code I guess it looks something like: > > while($sql_myrow = mysql_fetch_array($sql_result)) > { > > // we have an array of one row > > <use a foreach loop to stripslashes() on each element of the array> > > <use a foreach loop to nl2br() on each element of the array> > > <use a foreach loop to take each element (eg $sql_myrow["id"]) and > create a var ($id)> > > } > > > Of course I'm a way newbie on arrays, and I've read the manual, but am > unclear on the syntax for the above. > > > Ultimately, I'd like to put this all into a function which I call that > does it all in one hit, but I'll take that in a smaller step :) > > > Justin French > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]