tibberous Posted August 20, 2008 Share Posted August 20, 2008 I have a column with an enum('free','sale','full') named priceType When I try to get the value of priceType, it is just the string priceType. How can I get the value, or at least the index? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 20, 2008 Share Posted August 20, 2008 well lets see what you tried. Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 20, 2008 Author Share Posted August 20, 2008 select * from prices Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 20, 2008 Share Posted August 20, 2008 well from what you posted I don't see how that can ever work in php to get the result you desired please show us everything that will pertain to this Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 20, 2008 Author Share Posted August 20, 2008 print_r(mysql_fetch_assoc(mysql_query("select * from prices"))) It's a database query that's returning the field name rather an index and a value, what do you want to see? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 20, 2008 Share Posted August 20, 2008 well lets write it a bit more strucutred so it makes more sense <?php $q = "select * from `prices`"; $r = mysql_query($q) or die(mysql_error()."<Br /><br />".$q); if(mysql_num_rows($r) >0){ while($row = mysql_fetch_assoc($r)){ print_r($row); } } else{ echo "No Rows Found."; } ?> Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 20, 2008 Author Share Posted August 20, 2008 ... That's not actual code I'm using in my program. I just need to know whats up with enum's so I can fix it - I figured it would be easier to answer if I narrowed down the problem rather than pasting in three pages of code that you still can't run because you still don't have the database. Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 20, 2008 Author Share Posted August 20, 2008 Also, why would you wrap a mysql_fetch_assoc in an if mysql_num_rows. The second condition will always fail it the first does, it's redundant. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 20, 2008 Share Posted August 20, 2008 then you can take the literature and look at it yourself http://dev.mysql.com/doc/refman/5.0/en/enum.html and it won't fail it is design flow to verify you are workin on a resource that isn't rowless Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 i'm sure you'll be happy to get back on topic, so what value does it have as far as phpMyAdmin (or console) is concerned? and is this the case for all the rows, or just the one that gets returned first? (not sure if you're just print_r()ing the first returned row as your posted code implies or if that was just for show) Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 20, 2008 Author Share Posted August 20, 2008 If mysql_fetch_assoc is false, mysql_num_rows is false, it's stupid to explicitly check. It's also not at all relevant to the question, nor is rewriting my code with error handling. I'm using navicat, it displays the correct value, but I am pretty sure that is because it is fixing it. It is return the field name for all the rows. I think it might be like an html checkbox, where it's value is always the same, but it's checked property changes. And I looked at the doc's. It says I can get the index by refering to the field in 'interger context', but I'm not sure how to do that, and I'd really rather have the value as text. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 20, 2008 Share Posted August 20, 2008 have you tried using any other extraction methods, such as mysql_result() or mysql_fetch_array() with the numerical flag? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.