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}
Link to comment
https://forums.phpfreaks.com/topic/294979-category-php-code/
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
https://forums.phpfreaks.com/topic/294979-category-php-code/#findComment-1507131
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
https://forums.phpfreaks.com/topic/294979-category-php-code/#findComment-1507144
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.

Link to comment
https://forums.phpfreaks.com/topic/294979-category-php-code/#findComment-1507147
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
https://forums.phpfreaks.com/topic/294979-category-php-code/#findComment-1507150
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.