I have two tables. One which holds the user status content and the other holding the users. How do I write the query of the users to obtain the user record for their given streamitem in streamdata? At current times, its only grabbing the user that is at the top of the user table.
$check = "SELECT streamitem_id, streamitem_timestamp, streamitem_content FROM streamdata WHERE streamitem_creator="$user1_id." AND streamitem_id=".$last." AND streamitem_type_id=1 ORDER BY streamitem_timestamp DESC";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['streamitem_id'] = $resultArr['streamitem_id'];
$json['streamitem_timestamp'] = Agotime($resultArr['streamitem_timestamp']);
$json['streamitem_content'] = $resultArr['streamitem_content'];
mysqli_free_result($check1);
$check = "SELECT * FROM users";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['username'] = $resultArr['username'];
$json['id'] = $resultArr['id'];
$json['first'] = $resultArr['first'];
$json['middle'] = $resultArr['middle'];
$json['last'] = $resultArr['last'];
mysqli_free_result($check1);
-- Table structure for table `streamdata`
--
CREATE TABLE IF NOT EXISTS `streamdata` (
`streamitem_id` int(11) NOT NULL auto_increment,
`streamitem_type_id` int(11) NOT NULL,
`streamitem_creator` int(11) NOT NULL,
`streamitem_target` int(11) NOT NULL,
`streamitem_timestamp` datetime NOT NULL,
`streamitem_content` varchar(5000) NOT NULL,
PRIMARY KEY (`str
eamitem_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1953 ;
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`first` varchar(64) NOT NULL,
`middle` varchar(64) NOT NULL,
`last` varchar(64) NOT NULL,
`username` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=150 ;
Query to get user details and stream details for a given stream item:
Please note that it is bad practice to insert raw variable values into your queries. Especially if they come from user input. Look into mysqli_real_escape_string or try using prepared statements.