Need help with query

Started by HunterP, June 05, 2011, 02:17:21 PM

Previous topic - Next topic

HunterP

Hi,

I need help with this query :

$request = $smcFunc['db_query']('', '
SELECT id_board
FROM {db_prefix}topics
WHERE id_topic = {int:current_topic}',
array(
'current_topic' => $message['reported_topic'],
)
);


I need to perform one action if the number of rows is 0 or if the returned id_board has a specific ID. Normally I would use if ($smcFunc['db_num_rows']($request) == 0) if no data is returned, but IF any data is being returned, I have to check the id_board first. Any ideas how this can be combined in one IF?

Arantor

if (there are no rows)
{
  // do whatever
}
else
{
  call to mysql_fetch_row
  do whatever based on the id_board then
}
Holder of controversial views, all of which my own.


HunterP


Thanks, I could have thought about that, but there are 3 situations :

1. No rows
2. Good id_board
3. Bad id_board

In your example, 1 would be the if statement, 2 and 3 would be combined in the else statement.
The point is that I would like to combine 1 and 2, no rows and one specific id_board. All other id_boards can be ignored, I don't need an else statement.

HunterP

Quote from: Spuds on June 05, 2011, 04:10:00 PM
If you know the valid board_id's to begin with why not add them to the WHERE clause?

Ok thanks, I'll give it a try :)

HunterP


Other question, when moving a topic between boards, I need 2 queries?

if ($report_topic['id_board'] == $modSettings['recycle_board'])
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET   board_id = {int:report_board}
WHERE id_topic = {int:report_topic}',
array(
'report_board' => $modSettings['report_board_id'],
'report_topic' => $message['reported_topic'],
)
$smcFunc['db_query']('', '
UPDATE {db_prefix}messages
SET   board_id = {int:report_board}
WHERE id_topic = {int:report_topic}',
array(
'report_board' => $modSettings['report_board_id'],
'report_topic' => $message['reported_topic'],
)
);


HunterP


Another question, I need to update the icon in smf_messages when I know the id_topic, but only for the id_first_message. So I need a query which looks for the id_first_message for this certain id_topic and sets the icon in smf_messages where messages.id_message = topics.id_first_message.

Advertisement: