Note that there are some explanatory texts on larger screens.

plurals
  1. POfetch images from multiple mysql tables using php
    primarykey
    data
    text
    <p>I've been trying for the last couple of days to try and understand how to fetch data from multiple tables, but I cant say that I fully understood how it works. Anyway :) </p> <p>What I am trying to do is to fetch the images stored in multiple tables using a search bar to define the parameters i.e artist name (I know that storing an image in a database could cause many problems but its an exercise for the university so I cant really do much about it) </p> <p>So to be specific now. I have 5 tables called animaldata , cardata , landscapedata , peopledata and otherdata. Each of the table has the following fields : 1 id 2 artist_name 3 details 4 photo 5 phototype and 6 date. Where artist_name is the name of logged person who uploads the image and details is the caption , photo is the blob item to be saved and phototype is the .. well type of the image :P</p> <p>So what I want to do is when someone uses the search bar to search for an artist the code to fetch and display all the images from all the tables the artist has uploaded.</p> <p>Here's the code that I use to fetch the data from 1 table but I don't know how to alter it in order to search the other tables as well. </p> <p>That is the search.php</p> <pre><code>&lt;?php mysql_connect ("localhost","root","") or die (mysql_error()); mysql_select_db ("photo_album_db"); $term = $_POST['term']; $sql = mysql_query("select * from animaldata where artist_name like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo $row['details']; echo "&lt;/br&gt;"; echo "&lt;img src=getan.php?id=".$row['id']." width=250 height=200/&gt;"; echo "&lt;/br&gt;"; } ?&gt; </code></pre> <p>The Form of the search bar is the following : <code>&lt;form action="search.php" method="post"&gt;&lt;input type="text" name="term" /&gt;&lt;input type="submit" name="search" value="Search" /&gt;&lt;/form&gt;</code></p> <p>Thanks in advance for any suggestion , if you need more "clues" let me know :) :) :)</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.
 

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