Newbie: 'Correct' way of retreiving MySQL data
Posted: Thu Jun 04, 2009 3:18 pm
Seems like a billion different ways to skin this cat; and, I'm not sure what the most effective/best practice is. Just pulling basic information and displaying it from a database...
What I'm looking at:
That's simple and effective; but, I get 2 results for each entry. A numerical and associative index, example print_r output:
I don't know if this is a good idea? I mean, I can just step 2 when I iterate to output or whatever; but, I gotta think there's a smoother way with mysql_fetch_assoc or mysql_fetch_row. But, I'm not 100% on working with these yet, they seem to just grab a single row? So, some other iterations would have to happen to get all the results?
Hmm.. I still get numerical and associative indexing...
- I totally meant to put this in the databases sub-forum, if a mod could move it I would appreciate it, sorry.
What I'm looking at:
Code: Select all
$supervisee = mysql_query("SELECT * FROM tblEmployee WHERE DEPARTMENT = '" . $Dept . "'");
while($results = mysql_fetch_array($supervisee)) {
foreach ($results as $temp) {
echo $temp . " ";
}
echo "<br />";
} Code: Select all
Array ( [0] => 8******* [ID] => 8******* [1] => M***** [LAST_NAME] => M***** [2] => A***** [FIRST_NAME] => A***** [3] => M [MIDDLE_NAME] => M [4] => IT [DEPARTMENT] => IT [5] => HERE [LOCATION] => HERE ) Hmm.. I still get numerical and associative indexing...
Code: Select all
while($rowSupervisee = mysql_fetch_assoc($supervisee)){
for($i=0; $i < mysql_num_rows($supervisee); $i++) {
foreach ($rowSupervisee as $temp) {
echo $temp;
}
echo "<br />";
}
}