Topic: What am I doing wrong?

What is wrong about this query?

$result = $db->query('SELECT t.name, m.name AS metalname FROM '.$db->prefix.'metaltypes AS t INNER JOIN '.$db->prefix.'metals AS m ON m.id=t.metal_id WHERE t.id='.$id) or error('Unable to fetch metal type info', __FILE__, __LINE__, $db->error());
if (!$db->result($result))
    message($lang_common['Bad request']);
else
    $name = $db->fetch_assoc($result);
FluxBB - v1.4.8

Re: What am I doing wrong?

Moved to Programming
Enable debug mode, paste the full error

Re: What am I doing wrong?

It is no error, it just doesn't return anything from this:

<?php echo $name['metalname'], " - ", $name['name'] ?>
FluxBB - v1.4.8

Re: What am I doing wrong?

Anybody pleeeeeaaaasse?

FluxBB - v1.4.8

5 (edited by quaker 2007-06-12 20:59)

Re: What am I doing wrong?

lie2815 try this. im not sure what it does. and im trying to learn sql functions within punbb!
i was looking at my custom page menu seeing how it just pulls the name with a hyperlink.
Q

<?php
$result = $db->query('SELECT t.name, m.name AS metalname FROM '.$db->prefix.'metaltypes AS t INNER JOIN '.$db->prefix.'metals AS m ON m.id=t.metal_id WHERE t.id='.$id) or error('Unable to fetch metal type info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
  {
   
    ?>
    <div class="block">
    <h2 class="block2">Custom Menu</h2>
    <div class="box">
        <div class="inbox">
            <ul>
    <?php
    while($name = $db->fetch_assoc($result))
     
     
     echo "\t\t\t\t\t".'<li>'."\n\t\t\t\t\t\t".$name['metalname']."-".$name['name'].'</li>'."\n\t\t\t\t\t"."\n";
     
      ?>
        </ul>        
        </div>
    </div>
</div>
<?php
    }
?>
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: What am I doing wrong?

I think the while loop is not needed since the query should only return one result.

FluxBB - v1.4.8

Re: What am I doing wrong?

k, i really dont know what im doing.. so i thought that I would try to help and learn at the same time.

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

8 (edited by lie2815 2007-06-12 21:02)

Re: What am I doing wrong?

you actually did help...it works
GENIUS! lol
Thanks a lot!

EDIT: except that you forgot two of these: }...but even I can figure that one out wink

FluxBB - v1.4.8

Re: What am I doing wrong?

wow... i did it..hahaha... now im a sql master... lmao...

i looked at the code and thought that something  close to my cp menu..

give me a link so i can see it in actions....


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

10

Re: What am I doing wrong?

if you dont mind repost the working code.
that something that i see a lot people get stuff working and never post the working code.


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: What am I doing wrong?

Sorry. Here it comes:

$result = $db->query('SELECT t.name, m.name AS metalname FROM '.$db->prefix.'metaltypes AS t INNER JOIN '.$db->prefix.'metals AS m ON m.id=t.metal_id WHERE t.id='.$id) or error('Unable to fetch metal type info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
{
    while($name = $db->fetch_assoc($result))
    {
        $outputstring = "\t\t\t\t\t".'<li>'."\n\t\t\t\t\t\t".$name['metalname']." - ".$name['name'].'</li>'."\n\t\t\t\t\t"."\n";
    }
}
else
    message($lang_common['Bad request']);
?>

<div class="block">
            <h2><span><?php echo $outputstring ?></span></h2>
            <div class="box">
                <div class="inbox">
FluxBB - v1.4.8

12

Re: What am I doing wrong?

kewl.. thanks i hope i can try to help again...lol..


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: What am I doing wrong?

Another one:

$result = $db->query('SELECT full_name, desc, spec, color FROM '.$db->prefix.'alloys WHERE id='.$id) or error('Unable to fetch alloy information', __FILE__, __LINE__, $db->error());

Error message:

Unable to fetch alloy information

Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, spec, color FROM inventory_alloys WHERE id=1' at line 1 (Errno: 1064)
FluxBB - v1.4.8

Re: What am I doing wrong?

solved it. desc seems to be a special php word, so I obviously couldn't use it. I changed it to description and now everything works fine...

FluxBB - v1.4.8

15

Re: What am I doing wrong?

that good ! sorry i was not much of a help..
again im trying to learn it.
seem i can sorta debug it but not create it..haha

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: What am I doing wrong?

i googled it and the only thing I found that it probably was mistakenly taken as the DESC for descending (MySQL)...

FluxBB - v1.4.8

Re: What am I doing wrong?

Indeed. You could've just put the name in backticks (`) though.

18 (edited by lie2815 2007-06-13 20:15)

Re: What am I doing wrong?

oh ok...next time lol

EDIT: Elbekko's post no. 2000 ..... coming up ... lol

FluxBB - v1.4.8