Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does a leftjoin work while using a initialized prepared statement for MySQLI?
    primarykey
    data
    text
    <p>The user comes to this page from a different page where they click on a link and it is appended with a <code>?photo_id=</code> and then the id number. I want certain information to be available to the viewer when they arrive at this page.</p> <p>I want them to be able to see the photo, the photo name, and the photographers name. The first two are not a problem, because the <code>photo_id</code>, <code>photo_filename</code>, and <code>photo_title</code> are all in the same table. As soon as I try to get information about this photo that is on a different tabled called <code>photographers</code>, that's when I experience problems.</p> <p>Here's my code:</p> <pre><code>$sql = 'SELECT photos.photo_id, photos.photo_title, photos.photo_filename, photos.photographer_id, photographers.photographer_id, photographers.photographer_name FROM photos LEFT JOIN photographers ON photos.photographer_id = photographers.photographer_id WHERE photo_id = ?'; //initialize prepared statement $stmt = $conn-&gt;stmt_init(); if ($stmt-&gt;prepare($sql)) { $stmt-&gt;bind_param('i', $_GET['photo_id']); $stmt-&gt;bind_result($photo_id, $photo_title, $photo_filename, $photographer_id); $OK = $stmt-&gt;execute(); $stmt-&gt;fetch(); } </code></pre> <p>The first three variables(<code>$photo_id</code>, <code>$photo_title</code>, and <code>$photo_filename</code>) work fine and I can echo them out on my page, but the other variables that I added from the LEFTJOIN such as <code>photographers.photographer_id</code> and <code>photographers.photographer_name</code> which are from a different table, will not work. As it is know, the page totally breaks when I do add the extra column names on the SELECT line.</p> <p>I have a feeling it has something to with the amount of variables in the <code>bind_result()</code> function. I think they need to match the number of columns mentioned on the SELECT line, but I don't really want to create a variable for each one. </p> <p>Can anybody help me out?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload