PHP+MySQL PROBLEM: mysql_fetch_fields mess?

From: Date: Sat, 12 May 2001 06:40:22 +0000
Subject: PHP+MySQL PROBLEM: mysql_fetch_fields mess?
Groups: php.db 
Request: Send a blank email to php-db+get-9266@lists.php.net to get a copy of this message
Hi Everyone, Is it just me, or something is BADLY wrong with some MySQL functions? Is there some rule in which order to call mysql functions? I made following routine: <!--- code start --> <?php function prikazi_masku($tablica, $key_field, $key_value) { global $mycon_id; $data = mysql_query("SELECT * FROM $tablica WHERE $key_field='" . $key_value . "'", $mycon_id); if(!$data) { echo("MySQL Error: " . mysql_error() . "<br>"); return 0; }; if(mysql_affected_rows()==0) { echo('No data.<br>'); return 0; }; echo("<table border=1 bgcolor=#e0e0e0 bordercolor=#e0e0e0 cellspacing=1 cellpadding=3>"); echo("<tr bgcolor=#800080>"); // First field and its value I show in different color $meta = mysql_fetch_field ($data); $data_row = mysql_fetch_array ($data); // Here I want to get number of fields $n = mysql_num_fields($data); echo("<td><b><font color=white>$meta->name</td>"); echo("<td><b><font color=white>$data_row[0]</td></tr>"); $i = 1; // Now I show fields from index 1 to the last field while ($i < $n) { $meta = mysql_fetch_field($data); echo("<tr><td>$meta->name</td><td>$data_row[i]</td></tr>"); $i++; }; echo("</table>"); return 1; }; ?> <!-- code end --> Table I tried to show has 7 fields; first row (first field) show OK, but the rest ARE EMPTY!!! I tried to change the order of functions or anything, but it seems that after first acces of mysql_fetch_field something happens to $data_row?!? Can someone explain this and help me work out with it? TIA Davor

« previous php.db (#9266) next »