Jump to content
MakeWebGames

more sql problems.....


WarMad
 Share

Recommended Posts

i am using php 8 & PDO but i am trying to select enum from the database for friends and enemys list and im not getting an error but i can only get it to say that i am friends with them so it just says remove friends  i have tried several different things to get it to select if your friends or enemys but it will not let me do it here is my code

 

    $db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?');
    $db->execute([$i['userid'], $u['userid']]);
    $row = $db->fetch_row();
if(!$row) {
        $fri = '<a href="friends?add='.$profile_info->name.'">Add friend</a>';
        $ene = '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>';
    } else {
if($row['type'] = 'friend') {
    $fri = 'remove friend';
    $ene = '';


} else if($row['type'] = 'enemy') {
    $fri = '';
    $ene = 'Remove enemy';

}
}

 

Edited by WarMad
Changed name because realized it’s an sql problem
Link to comment
Share on other sites

$db->query('SELECT type, user, person FROM lists WHERE user = ? AND person = ?');
$db->execute([$i['userid'], $u['userid']]);
$row = $db->fetch_row();
$fri = (!$row ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($row['type'] == 'enemy' ? '' : ($row['type'] == 'friend' ? 'Remove Friend' : '')));
$ene = (!$row ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($row['type'] == 'friend' ? '' : ($row['type'] == 'enemy' ? 'Remove Enemy' : '')));

i would use this cuts down the code alot and does the same thing.

  

55 minutes ago, ags_cs4 said:

i will say its not an enum error should be an sql 

use == no just one

and !$row use the count function in pdo rowCount()

 

missed you are using MySQLi prepared statements and not PDO 

Edited by URBANZ
Link to comment
Share on other sites

  • WarMad changed the title to more sql problems.....
8 minutes ago, Magictallguy said:

I believe he's using a PDO wrapper I released a few years ago

yes i am

I found out that the sql is not working for some reason I double checked everything and I dont see anything wrong with it.

47 minutes ago, URBANZ said:

Solved lol

How is it solved?

Link to comment
Share on other sites

1 hour ago, WarMad said:

yes i am

I found out that the sql is not working for some reason I double checked everything and I dont see anything wrong with it.

How is it solved?

i mean the wrapper part not the actual sql lol was wondering if you was using a wrapper as thats not the correct way PDO does things thats MySQLi.

try this, not sure it will work, @Magictallguy will know more as he made the wrapper but im going by MySQLi prepared statments based on you using fetch_row();

 

MySQLi Version

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?");
$lists->bind_param('ii', $i['userid'], $u['userid']);
$lists->execute();
$list = $lists->fetch_row();
$fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : '')));
$ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

 

PDO Version

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person");
$lists->bindParam(':user', $i['userid'], PDO::PARAM_INT);
$lists->bindParam(':person', $u['userid'], PDO::PARAM_INT);
$lists->execute();
$list = $lists->fetch();   

$fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : '')));
$ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

 

Edited by URBANZ
Link to comment
Share on other sites

2 hours ago, URBANZ said:

i mean the wrapper part not the actual sql lol was wondering if you was using a wrapper as thats not the correct way PDO does things thats MySQLi.

try this, not sure it will work, @Magictallguy will know more as he made the wrapper but im going by MySQLi prepared statments based on you using fetch_row();

 

MySQLi Version

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?"); $lists->bind_param('ii', $i['userid'], $u['userid']); $lists->execute(); $list = $lists->fetch_row(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = ? AND person = ?");
$lists->bind_param('ii', $i['userid'], $u['userid']);
$lists->execute();
$list = $lists->fetch_row();
$fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : '')));
$ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

 

PDO Version

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person"); $lists->bindParam(':user', $i['userid'], PDO::PARAM_INT); $lists->bindParam(':person', $u['userid'], PDO::PARAM_INT); $lists->execute(); $list = $lists->fetch(); $fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : ''))); $ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

$lists = $db->prepare("SELECT type, user, person FROM lists WHERE user = :user AND person = :person");
$lists->bindParam(':user', $i['userid'], PDO::PARAM_INT);
$lists->bindParam(':person', $u['userid'], PDO::PARAM_INT);
$lists->execute();
$list = $lists->fetch();   

$fri = (!$list ? '<a href="friends?add='.$profile_info->name.'">Add friend</a>' : ($list['type'] == 'enemy' ? '' : ($list['type'] == 'friend' ? 'Remove Friend' : '')));
$ene = (!$list ? '<a href="enemys?add='.$profile_info->name.'">Add enemy</a>' : ($list['type'] == 'friend' ? '' : ($list['type'] == 'enemy' ? 'Remove Enemy' : '')));

 

I will give this a try I’m trying to wait and see if mtg reply’s first sense he did make the wrapper 

Link to comment
Share on other sites

You're using MTGs wrapper? I think the issue has just been overlooked, I use this wrapper for pretty much every PHP project i do.

I'm not sure if yours is any different than mine but I see you did this here: 

$row = $db->fetch_row();

His wrapper is meant to handle most of this for you, just try switching that particular line to: 

$row = $db->fetch();

I ran into this issue once and I swear that's how it was solved.

Edited by InverTed
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...