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));
return $data;

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

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));


if ($row['fan_count'] == 0 )
else {

what i am missing?

2 Years
Discussion Span
Last Post by SimonIoa

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

Votes + Comments
thanks pritaeas

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.