Re: [PHP-DB] Retrieving Rows - Can I Change The Order?

2001-07-28 Thread Thomas Lamy

 Von: Caleb Walker [mailto:[EMAIL PROTECTED]]
 Gesendet: Samstag, 28. Juli 2001 08:26
 An: Dave Watkinson; PHP-MySQL List
 Betreff: Re: [PHP-DB] Retrieving Rows - Can I Change The Order?
 
 
 
  Now then, I have changed a column in the table, and the 
 only way I found to
  change a data type is to delete the offending column and 
 then add it again.
 
  When I do the select now the new column, which was at 
 $row[3] is now always
  $row[39]. I don't mind this, because I know where it is, 
 but is there any
  way I can make it appear at $row[3] again? I'm sure you can 
 imagine when
  there are quite a few pages using this code it's easier to 
 reorder the
  columns in the select than to change all my if() codes!
 
You should use mysql_fetch_array() instead of mysql_fetch_row(), so you can
refer to your columns by name, as in:
$q = mysql_query(select id,name from address;);
$a = mysql_fetch_array ($q);
== now you can use $a['id'] and $a['name'] to get the field's values.

I found it always good practice to name all affected columns in a query, so
you have no pain  if your columns get mixed by db alters.


Thomas


-- 
PHP Database 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]




Re: [PHP-DB] Retrieving Rows - Can I Change The Order?

2001-07-27 Thread Caleb Walker


 Now then, I have changed a column in the table, and the only way I found to
 change a data type is to delete the offending column and then add it again.

 When I do the select now the new column, which was at $row[3] is now always
 $row[39]. I don't mind this, because I know where it is, but is there any
 way I can make it appear at $row[3] again? I'm sure you can imagine when
 there are quite a few pages using this code it's easier to reorder the
 columns in the select than to change all my if() codes!

Maybe I am missing what you are trying to do but it sounds like you are just 
trying to sort your columns.  If that is what you are asking then why dont 
you do your query like this:
select * from $table where $column = '$value' ORDER BY $column
I hope this is what you were asking and that is helps you out.


 By the way, I know I can be explicit by SELECTing each column by name, but
 I'ds rather use a SELECT * fror this partucular instance.

 Any ideas? Or am I just being lazy (it's been a long night after all!)?


 TIA


 Dave

-- 
PHP Database 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]