I have a problem with mysqli syntax. I really can't see what the problem is in this code. I dont know much about it.
When i use it on a function like this

public function Somefunction()
{

$query=mysqli_query($this->db,"SELECT title,url,img FROM table WHERE status='1' ORDER BY id DESC")or die(mysqli_error($this->db));
while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$data[]=$row;
}
return $data;
}

its ok when i am trying to use it like i did natively on a page it doesnt work.

<?php 
echo '<label style="font-size:16px">'. $message.'</label><label> at </label>
<a style="font-size:14px">' .$venue.'</a>';?><br><br/>
<?php echo '<label>'. date('l, F d, Y H:i a', strtotime($dategig)).'</label>';
$query=mysqli_query($this->db,"SELECT fan_count FROM messages WHERE msg_id='$msg_id'")or die(mysqli_error($this->db));
$row=mysqli_fetch_array($query,MYSQLI_ASSOC);

$show1='style="display:block;"';
$show2='style="display:block;"';

if ($row['fan_count'] == 0 )
{
    $show1='display:block;';
    $show2='display:none;';
}
else {
    $show1='display:none;';
    $show2='display:block;';
}
?>

what i am missing?

Recommended Answers

All 4 Replies

Line 5 uses $this which references the current object instance, which isn't available in your script.

commented: thanks pritaeas +2

I don't get what you are trying to express. Your first script has no relation to the second one. Can you express yourself vividly?

why dont you consider using procedural instead of object oriented?

that way you have

$link = mysqli_connect('yourHost','username','password','database');

$q = SELECT fan_count FROM messages WHERE msg_id='$msg_id'";

$result = mysqli_query($link,$q) or die('sorry an error ocurred');

$resultRows = mysqli_fetch_assoc($result); 

Then you can access the data like so

echo $resultRows['column']; 

That should work.

Thanks Pritaeas. I should have called it as an function $this->db = $db; I it was a stupid mistake Gideon. The two posts had nothing to do with each other. I just posted them as examples. Pritaeas has shared the solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.