harkly Posted November 21, 2008 Share Posted November 21, 2008 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."; } Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/ Share on other sites More sharing options...
rkrass Posted November 21, 2008 Share Posted November 21, 2008 not really sure what your asking. can you explain a bit more... Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695471 Share on other sites More sharing options...
Maq Posted November 21, 2008 Share Posted November 21, 2008 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. Do a JOIN. What's your question? Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695473 Share on other sites More sharing options...
harkly Posted November 21, 2008 Author Share Posted November 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695480 Share on other sites More sharing options...
rkrass Posted November 21, 2008 Share Posted November 21, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695551 Share on other sites More sharing options...
harkly Posted November 21, 2008 Author Share Posted November 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133662-query-question/#findComment-695589 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.