0

I want to fetch contents of two separate category and insert them in two different boxes. I have written the query like this:

$query = mysql_query(sprintf("SELECT * FROM ".DB_PREFIX."_links WHERE cat = %d LIMIT %d" , 4, 3));

But can we write 2 or more query in one query? like :"select * from blah where cat = (3, 4, 5)"

EDIT: alt text

Thanks in advance

2 Answers 2

4

Update 2

To load your data in a specific div, you can store the result in an array and later echo it where you want like this:

$result = mysql_query(...........);

$i = 0;
$data = array();

while($row = mysql_fetch_array($result)){
    $data[$i] = $row;
    $i++;
}

HTML:

<!-- For div 1 -->
<div>
  <?php echo $data[0]['fieldName']?>
</div>

<!-- For div 2 -->
<div>
  <?php echo $data[1]['fieldName']?>
</div>

<!-- For div 3 -->
<div>
  <?php echo $data[2]['fieldName']?>
</div>

Update

You can do something like this:

    $result = mysql_query(...........);
    while($row = mysql_fetch_array($result)){
      echo '<div>' . $row['fieldName'] . '</div>'
    }

This way each record will appear in different div.


But can we write 2 or more query in one query? like :"select * from blah where cat = (3, 4, 5)"

You can do so with IN operator:

select * from blah where cat IN (3, 4, 5)

The IN operator allows you to specify multiple values in a WHERE clause.

More Information:

Sign up to request clarification or add additional context in comments.

3 Comments

After query, how can I separate each result to separate div ? For example, category 1 contents in <div>content of category1</div> , <div>content of category2</div>
This: <?php echo $data[0]['fieldName']?> will show only one row. I want to make only one query and then separate them. All contents of one category in separate box. I think I have to separate the query :((
@phpExe: You can use print_r($data) to see the data and use it however you like :)
2

just use the IN statement of SQL

SELECT * FROM _links WHERE cat IN (3,4,5)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.