yandoo Posted August 28, 2009 Share Posted August 28, 2009 Hi there, Im writing a little php project to store vegetables and various attributes of them in a database. I have 2 tables; Vegetable table and Sow table. Vegetable table VegeID Name Etc Sow table SowID VegeID* Jan Feb Mar Apr Etc The Sow table contains the months jan to dec and is either a 1 or a 0 if that vegetable can be sown on that month. I want to SELECT only the vegetables from the Vegetable Table in the database (as they contain more details)that CAN be sown in the current month (or perhaps by user inputted month?). im just not sure where to start with this one and would really appreciate any help you wonderful people could offer. Thank You Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/ Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 $month = 'mar'; $sql = 'select V.VegeID,V.Name from vegetableTable V,sowTable S where S.'.$month.' = 1 and V.VegeID = S.VegeID'; Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/#findComment-908434 Share on other sites More sharing options...
yandoo Posted August 29, 2009 Author Share Posted August 29, 2009 Thank you very much for the reply! Ill give it a go today Thanks again Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/#findComment-908878 Share on other sites More sharing options...
yandoo Posted August 29, 2009 Author Share Posted August 29, 2009 Hi there, Ive followed your method and adapted it slightly to: <?php $month = 'Jul'; mysql_select_db($database_connect, $connect); $query_sql = 'select V.VegeID,V.Name from vegetable V,outdoorsowtime S where S.'.$month.' = 1 and V.VegeID = S.VegeID'; $sql = mysql_query($query_sql, $connect) or die(mysql_error()); $row_sql = mysql_fetch_assoc($query_sql); echo $sql; // echo $query_sql; mysql_free_result($sql); ?> It comming up with an error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in E:\wamp\www\greenlife\view_vege.php on line 13 Resource id #4 Any ideas what im missing here? Thank You Just realised: $row_sql = mysql_fetch_assoc($query_sql); should be : $row_sql = mysql_fetch_assoc($sql); Still get the error: Resource id#4 Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/#findComment-908953 Share on other sites More sharing options...
yandoo Posted August 29, 2009 Author Share Posted August 29, 2009 I alos realise i need a While statement in there and the code is now: <?php $month = 'Jul'; mysql_select_db($database_connect, $connect); $query_sql = 'select V.VegeID,V.Name from vegetable V,outdoorsowtime S where S.'.$month.' = 1 and V.VegeID = S.VegeID'; $sql = mysql_query($query_sql, $connect) or die(mysql_error()); while ($row = mysql_fetch_assoc($sql)) { echo $row['Name']."<br />\n"; echo $sql; } mysql_free_result($sql); ?> I think its working but only halve 1 recordi n db so gona add and test... Thanks Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/#findComment-908962 Share on other sites More sharing options...
yandoo Posted August 29, 2009 Author Share Posted August 29, 2009 Fantastic It Works! Thank You Link to comment https://forums.phpfreaks.com/topic/172299-solved-select-records-by-months/#findComment-908980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.