sford999 Posted February 20, 2009 Share Posted February 20, 2009 Hi, I have this database where it holds info on models. Type '1' = Fashion Type '2' = Glamour Type '3' = Fashion & Glamour. I have this query: <?php $sql = "SELECT * FROM models WHERE type = '2' AND type = '3' AND visible = '1' ORDER BY id"; ?> However the problem is that its not showing any of the models on the page. If I change the query to this below it works perfectly. <?php $sql = "SELECT * FROM models WHERE type = '2' AND visible = '1' ORDER BY id"; ?> What/Where have I done/gone wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146135-solved-select-multiple-type-from-single-mysql-column/ Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 <?php // mysql connection information here. $sql = "SELECT * FROM models WHERE type = '2' AND visible = '1' ORDER BY id"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { echo $row['type'] . "<br />"; } ?> mysql I would suggest reading up on PHP's mysql functions. Quote Link to comment https://forums.phpfreaks.com/topic/146135-solved-select-multiple-type-from-single-mysql-column/#findComment-767174 Share on other sites More sharing options...
sford999 Posted February 20, 2009 Author Share Posted February 20, 2009 That doesn`t really help me a great deal, I'm trying to fetch type = "2" AND type = "3" from the same table column as some of the models are fashion only (type 1), glamour only (type 2) and some do both fashion and glamour (type 3). This is the code I have at present. <?php $sql = "SELECT * FROM models WHERE type = '2' AND type = '3' AND auth = '1' ORDER BY id"; $result = mysql_query($sql) or die(sql_error(mysql_error(), $sql)); if(!mysql_num_rows($result)) { echo 'Error'; } $column=1; while($row = mysql_fetch_array($result)) { extract($row); if ($column == 1) { // Begin row in table echo '<tr>'; } echo '<a href="model.html?'.$id.'"><img src="models/'.$img_id.'" width="94px" height="128px" /><br /><h3>'.$name.'</h3></a>'; $column++; // When you've looped enough, end the row. if ($column == 6) { echo '</tr>'; $column=1; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146135-solved-select-multiple-type-from-single-mysql-column/#findComment-767178 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 $sql = "SELECT * FROM models WHERE type IN(2, 3) AND auth = '1' ORDER BY id"; Sorry, mis read what you were asking. You want either the IN() operator in MySQL or to use a "OR" operator, as you want type to be Either 2 OR 3. Quote Link to comment https://forums.phpfreaks.com/topic/146135-solved-select-multiple-type-from-single-mysql-column/#findComment-767184 Share on other sites More sharing options...
sford999 Posted February 20, 2009 Author Share Posted February 20, 2009 Perfect Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146135-solved-select-multiple-type-from-single-mysql-column/#findComment-767190 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.