Jump to content

category php code ?


Davie33

Recommended Posts

Hi guys hoping you can help with this code of mine.

I seem to be getting an error ,i know its the query but tried a few to fix it without joy.

<?php
$catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']);
$catname = $catcheck->fetch_array(MYSQLI_ASSOC);
if ($setting['seo']=='yes') { ?>
    <a href="<?php echo $setting['siteurl'];?>category/<?php echo $row['category'];?>/1.html" title="<?php echo ucfirst($catname['name']);?>"><?php echo ucfirst($catname['name']);?></a>
    <?php
} else { ?>
    <a href="<?php echo $setting['siteurl'];?>index.php?act=cat&id=<?php echo $row['category'];?>" title="<?php echo ucfirst($catname['name']);?>"><?php echo ucfirst($catname['name']);?></a>
    <?php
}
?>

this is the line thats causing the error.

$catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']);

error

    Error No: 0 - MySQL error 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 '' at line 1 
    Query: "SELECT `name` FROM `categories` WHERE `id` = "
    #0 /public_html/arcade/templates/minix_25/game.php(236): yasDB_select('SELECT `name` F...')
    #2 {main}
Edited by Davie33
Link to comment
Share on other sites

$row['category'] is used in your query to return records from your table where the id matches. Problem is $row['category'] is not populating the query with a value as shown in the error message (query highlighted in red)

 

 

Error No: 0 - MySQL error 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 '' at line 1
    Query: "SELECT `name` FROM `categories` WHERE `id` = " <-- no value provide for id resulting in the error above
    #0 /public_html/arcade/templates/minix_25/game.php(236): yasDB_select('SELECT `name` F...')
    #2 {main}

 

Wherw is $row['category'] defined? Are you sure that is the correct variable to use in the query?

Link to comment
Share on other sites

What's the surrounding code? Given the variable name $row, it's possible the code is trying to run the select query inside a loop, which isn't a good idea. If that is what's actually happening, you're probably going to want to rework the initial query to use a join in order to bring back the entire record set with a single call to the database.

Link to comment
Share on other sites

Hi what am looking for is when i go to the game page that code above is to give the name of the category the game is from.

For some reason the code does work but still give out the error as thats whats on my site atm is that code.

Check my link below then go to the main game page on any game you will see the name of the cat the game is from.

Edited by Davie33
Link to comment
Share on other sites

Right, and that's why we're asking you to supply the surrounding code. $row['category'] either isn't being set, or it's being set incorrectly. However, without the surrounding code, there's no way to tell where, how, or why.

Link to comment
Share on other sites

Am not to sure but i think this has solved it.

 

 

<?php
$catcheck = yasDB_select("SELECT `name` FROM `categories` WHERE `id` = " . $row['category']);
$catname = $catcheck->fetch_array(MYSQLI_ASSOC);
if ($id = $row['category']) {
if ($setting['seo']=='yes') { ?>
    <a href="<?php echo $setting['siteurl'];?>category/<?php echo $row['category'];?>/1.html" onMouseover="showhint('<b><?php echo ucfirst($catname['name']);?></b>',this, event, 'auto')"><?php echo ucfirst($catname['name']);?></a>
    <?php
} else { ?>
    <a href="<?php echo $setting['siteurl'];?>index.php?act=cat&id=<?php echo $row['category'];?>" onMouseover="showhint('<b><?php echo ucfirst($catname['name']);?></b>',this, event, 'auto')"><?php echo ucfirst($catname['name']);?></a>
    <?php
}
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.