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']);
You are not logged in. Please login or register.
PunBB Forums → Programming → 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']);
Looks correct, yes.
ok does this code after it make sense?
if ($db->num_rows($result))
$restore = '0';
else
$restore = '1';
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?
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?
$db->num_rows() should do.
Off topic, elbekko did you check your email?
I like my current avatar better, but thank you
Odd enough, your message was marked as spam.
heh, alright cool.
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
}
?>
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';
PunBB Forums → Programming → query help
Powered by PunBB, supported by Informer Technologies, Inc.