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
https://forums.phpfreaks.com/topic/133662-query-question/
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
https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695480
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
https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695589
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.