Jump to content

[SOLVED] Select multiple type from single mysql column


Recommended Posts

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

 

<?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.

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;
}
}
?>

$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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.