Jump to content

Query Question


harkly

Recommended Posts

Could someone point me in the right direction.

 

I am passing a variable to 6 tables and I want them to print out separately, on the same page, then the user will be able to click on them. I'm not sure if I need to do a JOIN or if I should do some type of statement, or do 6 different queries.

 

Here's my code simplified, I am using the if/elseif statement with nested if/else statements in the "artist" & "image". My question is on the last 'else'.

 

if ($field == "artist")
{
echo "I will for the artist only.";
}

elseif ($field == "image")
{
echo "I will check for images only.";
}

else
{
echo "I will search everywhere.";
}

 

 

 

 

Link to comment
Share on other sites

I need to know if I should do a JOIN or if statement to pull information from 6 tables. So the information from each table will be printed on separate lines.

 

for instance

 

With your search we found

 

Artist -

Name 1

Name 2

etc.

 

Art Work -

Title 1

Title 2

Title 3

 

Movement -

Movement 1

Movement 2

 

 

 

I was thinking that I could do something like this

 

else
{

    $artist = mysql_query("SELECT * FROM artist WHERE fullName LIKE '%$search%' ORDER BY lastName");

    $image = mysql_query("SELECT image.imgid, image.title, image.artid, image.keywords, image.dt, artist.artid, artist.fullName FROM image LEFT JOIN artist ON artist.artid = image.artid WHERE image.title LIKE '%$search%' ORDER BY title") or die(mysql_error());

    //$genre = mysql_query("SELECT 

    //$medium = mysql_query("SELECT 

    //$movement = mysql_query("SELECT 

    //$period = mysql_query("SELECT 

    $num_artist=mysql_num_rows($artist);

    $num_image=mysql_num_rows($image);

      //artist

      if ($num_artist != "0")
        {
  echo "<h1><b>Names of Artist(s)</b> <br><br>";
  $count = count(0);

            //grab all the content

            while ($r=mysql_fetch_array($artist))
              {	

                  $artid=$r["artid"];
                  $fullName=$r["fullName"];
                  $nationality=$r["nationality"];
                  $dob=$r["dob"];
                  $dod=$r["dod"];

                  echo $count++;
                  echo ". <a href='artist.php?artid=$r[artid]'>".$fullName."</a>, ".$dob." - ".$dod.", ".$nationality." <br>";
              }
         }


      //image



      else ($num_image != "0")
        {
          $count = count(0);

          //grab all the content

            while ($r=mysql_fetch_array($image))
              {	
                $title=$r["title"];
                $imgid=$r["imgid"];
                $dt=$r["dt"];
                $artid=$r["artid"];
                $fullName=$r["fullName"];

                //display the row
                
                echo $count++; 	
                echo ". <a href='image.php?imgid=$r[imgid]'><img src=\"image/$imgid\" border=0 ></a>, <i>".$title."</i>, ".$dt." by <a href='artist.php?artid=$r[artid]'>".$fullName."</a><br>";
              }
        }


}

 

Getting an error - syntax error, unexpected '{' in /home/content/a/r/t/art2294/html/ifElse5.php on line 233

 

 

but would that work? I would do a query for each table.

Link to comment
Share on other sites

the join would work if you want to draw cumulative results

if you want to break out each section:

Artist -

Name 1

 

Art Work -

Title 1

 

Movement -

 

would require separate queries to that table only..

 

(assuming i understand what your trying to do)

Link to comment
Share on other sites

I would like to do try separate queries but not sure how to call them.

 

In my head it works like this

 


//Queries
$image
$artist
$genre
$movement

$num_artist=mysql_num_rows($artist);
$num_image=mysql_num_rows($image);
$num_image2=mysql_num_rows($genre);


if ($num_artist != "0")
do this
and if ($num_image != "0")
do this
and if ($num_genre != "0")
do this 
etc..

 

I have the queries working and can call them but not all together on the same page consecutively.

 

 

------------

 

 

Can I use a bunch of if statments?

 

 

 
if ($num_artist != "0")
do this

   if ($num_image != "0")
do this

etc.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.