Topic: query help

Is this query correct?

$db->query('SELECT id FROM '.$db->prefix.'posts WHERE first_post=1 AND topic_id='.$deleted_post['topic_id'].' AND id!='.$deleted_post['id']);
FluxBB - v1.4.8

Re: query help

Looks correct, yes.

Re: query help

ok does this code after it make sense?

if ($db->num_rows($result))
    $restore = '0';
else
    $restore = '1';
FluxBB - v1.4.8

Re: query help

This is what I am trying to do:

while ($deleted_post = $db->fetch_assoc($result))
{
$poster = '<a href="profile.php?id='.$deleted_post['poster_id'].'">'.$deleted_post['poster'].'</a>';
$db->query('SELECT id FROM '.$db->prefix.'posts WHERE first_post=1 AND topic_id='.$deleted_post['topic_id'].' AND id!='.$deleted_post['id']);
if ($db->num_rows($result))
    $restore = '0';
else
    $restore = '1';

But $restore always seems to be 0, which should not be true always.
Is $db->num_rows the right function? What should I use instead? $db->result?

FluxBB - v1.4.8

Re: query help

I am not really good in php. I am trying to find out if the query fetches a result or not. Which mysql function do I have to use?

FluxBB - v1.4.8

Re: query help

anybody... pleeeeeeeeeaaaazzzzeeee?

FluxBB - v1.4.8

Re: query help

$db->num_rows() should do.

Re: query help

Off topic, elbekko did you check your email?

Re: query help

I like my current avatar better, but thank you tongue

Odd enough, your message was marked as spam.

Re: query help

heh, alright cool.

Re: query help

thanks guys. one more question... this query is inside another query ($db->fetch_assoc($result) and stuff), but it looks like the query is only run once, although it should run once for every single one of the loops of the bigger queries. How can I fix that? Here is the whole code:

$result = $db->query("SELECT p.id, p.poster, p.poster_id, p.message, p.topic_id, p.first_post, t.subject, t.forum_id FROM ".$db->prefix."posts AS p INNER JOIN ".$db->prefix."topics AS t ON t.id=p.topic_id WHERE p.deleted=1");
if (!$db->num_rows($result))
    echo 'No deleted posts.';
else
{
?>
<table>
<tr>
<th style="width:250px;">Subject</th>
<th style="width:300px;">Message</th>
<th style="width:100px;">Poster</th>
</tr>
<?php
while ($deleted_post = $db->fetch_assoc($result))
{
$poster = '<a href="profile.php?id='.$deleted_post['poster_id'].'">'.$deleted_post['poster'].'</a>';
$db->query('SELECT id FROM '.$db->prefix.'posts WHERE first_post=1 AND topic_id='.$deleted_post['topic_id'].' AND id!='.$deleted_post['id']);
if ($db->num_rows($result) == '1')
    $restore = '0';
else
    $restore = '1';
?>
<form id="postlog" method="post" action="admin_loader.php?plugin=AMP_Deleted_post_log.php&id=<?php echo $deleted_post['id'] ?>&topic=<?php echo $deleted_post['topic_id'] ?>&forum=<?php echo $deleted_post['forum_id'] ?>&first_post=<?php echo $deleted_post['first_post'] ?>">
<tr>
<td style="width:250px;"><?php echo $deleted_post['subject'] ?></td>
<td style="width:300px;"><?php echo $deleted_post['message'] ?></td>
<td style="width:100px;"><?php echo $poster ?></td>
<td>
<input type="submit" name="delete" value="Delete forever" />
</td>
<td>
<input type="submit" name="restore" value="Restore" <?php if ($restore == '0') echo 'disabled ' ?>/>
</td>
</tr>
</form>
<?php
}
?>
</table>
<?php
}
?>
FluxBB - v1.4.8

Re: query help

anybody?

FluxBB - v1.4.8

13

Re: query help

You have to assign a second var to the inner statement.

Like

while ($deleted_post = $db->fetch_assoc($result))
{
$poster = '<a href="profile.php?id='.$deleted_post['poster_id'].'">'.$deleted_post['poster'].'</a>';
$inner = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE first_post=1 AND topic_id='.$deleted_post['topic_id'].' AND id!='.$deleted_post['id']);
if ($db->num_rows($inner) == '1')
    $restore = '0';
else
    $restore = '1';
The German PunBB Site:
PunBB-forum.de

Re: query help

omg i am an idiot...
THANK YOU SO MUCH!!!

FluxBB - v1.4.8