Drupal 7 Multiple Select Joins Syntax - sql

Having real trouble getting my head around multiple joins. Can anyone tell me why this is wrong please?
*EDIT*
$query = db_select('node', 'n');
$query->join('file_usage', 'fu', 'fu.id = n.nid');
$query->join('field_data_field_featured_image', 'ffimage', 'ffimage.entity_id = n.nid');
$query->join('file_managed', 'fm', 'fm.fid = n.nid');
$query
->fields('fu', array('id'))
->fields('fm', array('filename'))
->fields('ffimage', array('field_featured_image_title'))
->fields('n', array('nid', 'title'))
->condition('n.type', 'work')
->orderby('n.nid', 'DESC')
->range(0, 20);
$result = $query->execute();
foreach ($result as $record) {
echo '<li>';
echo '<div class="home_text"><h1>'.$record->title.'</h1></div>';
echo '<a href="...some_node/';
echo $record->id;
echo '">';
echo '<img src="...some_files/';
echo $record->filename;
echo '" width="960px" height="615px" />';
echo '</a>';
echo '</li>';
}

Related

Could not find RETS data in TREB VOW Data Access

This is connection file
date_default_timezone_set("Canada/Eastern");
require_once("vendor/autoload.php");
$config = new \PHRETS\Configuration;
$config->setLoginUrl('http://retsau.torontomls.net:6103/rets-treb3pv/server/login')
->setUsername('XXXX1')
->setPassword('76XXXXX')
->setRetsVersion('1.7');
$rets = new \PHRETS\Session($config);
$connect = $rets->Login();
echo '<pre>';
var_dump($connect);
echo '</pre>';
if($connect)
{ echo "connetced";
else{
echo 'not connected';
}
After connection could not find any data
$results = $rets->Search('Property', 'A', '*', ['Limit' => 3, 'Select' => 'LIST_1,LIST_105,LIST_15,LIST_22,LIST_87,LIST_133,LIST_134']);
foreach ($results as $r) {
echo '<pre>';
var_dump($results);
echo '</pre>';
}
I need to display this data after connection
First you should check TREB metadata, find correct field names and use them in the search. Moreover, you should send a query as 3rd argument of Search function.

SQL being a jerk again

I have the script I use that displays things from a table in my database, but it keeps giving me this error:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\raynerblogger1\posts.php on line 21
someone please help
$sql = "SELECT * FROM blogs;";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo "<div id='message'>";
echo $row['author']; echo(':') . "<br>";
echo $row['post'] . "</div>" . "<br>" . "<br>" . "<br>";
}
Try this, I edited line 1 and 6:
$sql = "SELECT * FROM blogs";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo "<div id='message'>";
echo $row['author'].":". "<br>";
echo $row['post'] . "</div>" . "<br>" . "<br>" . "<br>";
}

how to get wordpress post with by category with images

I have installed wordpress and opencart in same database. Trying to get wordpress posts table inside opencart module. got the mysql query to fetch all information except image. I dont why images are different from the post in loop of result. Kindly guide, following is the code.
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tablename";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}
$sql = "SELECT * FROM wp_posts WHERE post_type = 'attachment' ORDER BY ID DESC LIMIT 3";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<div class="col-sm-4">';
echo "Post ID: " . $row["ID"] . " / ";
echo "Post Title: " . $row["post_title"] . " / ";
echo "Post Title: " . $row["post_date"] . " / ";
echo '<img src="' . $row['guid'] . '" class="img-responsive">';
echo '</div>';
}
} else {
echo "0 results";
}
Run your query in phpMyAdmin and check if result you got is the same as you want (you get those pictures that you want).
Then I advise you to set the checkpoint inside the loop and look at the data. Debugging is a very powerful thing in finding errors, it's time to start using it

get each post number of views count pdo

i am new in pdo. want to echo number of times post viewed. each time a user view it will add +1 autometically. i created a table views that type int length 16. my code is below
<?php
try {
$stmt = $db->query('SELECT postID, postTitle, postDesc, postDate, views FROM blog_posts ORDER BY postID ASC');
while($row = $stmt->fetch()){
echo '<div>';
echo '<h1>'.$row['postTitle'].'</h1>';
echo '<p>Posted on '.date('jS M Y H:i:s', strtotime($row['postDate'])).'</p>';
echo '<p>'.$row['postDesc'].'</p>';
echo $row['views']; echo "times";
echo '<p>Read More</p>';
$stmt = $db->prepare('UPDATE blog_posts SET views = views+1 WHERE postID = :postID') ;
echo '</div>';
}
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
You just prepare update statement not execute so execute the prepare statement .
$stmt = $db->prepare('UPDATE blog_posts SET views = views+1 WHERE postID = :postID') ;
$stmt->execute(array(':postID'=>$row['postID']));

SQL Results Pagination

I'm having a bit of trouble paginating my sql query results using PHP. I have tried a few different solutions but have had no success so far. Would someone be able to help me please? Below is my current code I use to display all results however I'd like them splitting into pages of 50.
<?
//query
$data = mysql_query("SELECT * FROM names");
//counts_result
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "ERROR";
}
else {
echo "<div class='search_result_output'>
SEARCH SUCCESS
</div><hr>";
}
?>
<?
//display results
while($result = mysql_fetch_array( $data ))
{
echo "<div class='panel panel-default'>";
echo "<div class='panel-heading'>";
echo "<h4 class='panel-title'>";
echo $result['name'];
echo "</h4>";
echo "</div>";
echo "<div class='game_actions' style='float:right; margin-top:-40px; margin-right:10px;'>";
echo "<a data-toggle='collapse' class='btn btn-custom' data-parent='#accordion' href='#".$result['id']."' title='More Info on ".$result['name']."'><i class='fa fa-plus'></i></a>";
echo "</div>";
echo "<div id='".$result['id']."' class='panel-collapse collapse'>";
echo "<div class='panel-body'>";
echo $result['name'];;
echo "</div>";
echo "</div>";
echo "</div>";
}
}
?>
You have this:
$data = mysql_query("SELECT * FROM names");
instead use this:
$page = (isset($_GET["page"])) ? $_GET["page"] : "0";
$data = mysql_query("SELECT * FROM names limit ".$page.", 50");
Display your links accordingly; add the page value to them. Your paging depends on the get parameter named "page".
EDIT:
If you want to display a link pointing to the 5th page, for instance, then:
echo '5';
4 * 50 = page index * page size. Page index is 4, as on the first page you have no offset. It is difficult to add any more help, since I do not know what kind of paging you need. However, this edit should help you to start solving your problem.
try something like this query and then just just change parameter i.e (3 and 8)
Select * from
(select Id,Name ,ROW_NUMBER() over (order by Id) as RowNum from Person.dbo.pers
) tbl
Where tbl.RowNum between 3 and 8
it gets 3 to 8 rows