jeger003 Posted February 1, 2009 Share Posted February 1, 2009 i finally got this together with the help of everyone here......but when i run it my footer goes away you can see i have two queries run........one in the while()......reason for that is i needed to join the two tables but couldn't use JOIN cause i needed to match to different fields thank you guys! <?php $get_subject = $_GET['orderedby']; switch($get_subject) { case mth; $value_to_find = 'math'; break; case 'sci'; $value_to_find = 'Science'; break; case 'hist'; $value_to_find = 'History'; break; case 'eng'; $value_to_find = 'English'; break; case 'gov'; $value_to_find = 'Government'; break; case 'fit'; $value_to_find = 'Health'; break; case 'lang'; $value_to_find = 'Foreign'; break; case 'comp'; $value_to_find = 'Computer'; break; case 'busin'; $value_to_find = 'Business'; break; case 'oth'; $value_to_find = 'Other'; break; } $query_title = mysql_query("SELECT title, id, image,search_text FROM listings WHERE search_text LIKE '%$value_to_find%' AND live = 1"); $num = mysql_num_rows($query_title); if($num > 0) { echo "<table>"; while ($fetch = mysql_fetch_array($query_title) ) { if($fetch['image'] > 0) { $image = mysql_query("SELECT thumb_url,full_filename,listing_id,image_width,image_height FROM listings_urls WHERE listing_id = '".$fetch['id']."'"); $fetch_file = mysql_fetch_array($image); if($fetch_file['thumb_url'] == 0) { $thumb_url = "images/".$fetch_file['full_filename']."'"; $width = $fetch_file['image_width']; $height = $fetch_file['image_height']; } else { $thumb_url = "images/".$fetch_file['thumb_url']."'"; $width = $fetch_file['image_width'] ; $height = $fetch_file['image_height'] ; } } else { $thumb_url = 'images/nopic.gif'; } echo "<tr>"; echo "<td>".$fetch['title']."</td>"; echo "<td><img src='http://mysite.com/$thumb_url' width='$width' height='$height'></td>"; echo "</tr>"; } } else { echo "no subject found!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/ Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 Put: error_reporting(E_ALL); and ini_set('display_errors', '1'); at the top of your script. Also, you could use a join: SELECT l.title, l.id, l.image, l.search_text, lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height FROM listings l JOIN listings_urls lu ON lu.listing_id = l.id WHERE search_text LIKE '%$value_to_find%' AND live = 1 Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752005 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 hey corbin, thanks for the reply. awesome tip for finding errors!! i used the error reporting......got a lot of errors....mostly things undefined....but i fixed them and i added the JOIN tables you wrote.....but now when i run the query it always echo's "no subject found!" which i guess means its running it but not running the if()'s update: <?php $get_subject = $_GET['orderedby']; switch($get_subject) { case 'mth'; $value_to_find = 'math'; break; case 'sci'; $value_to_find = 'Science'; break; case 'hist'; $value_to_find = 'History'; break; case 'eng'; $value_to_find = 'English'; break; case 'gov'; $value_to_find = 'Government'; break; case 'fit'; $value_to_find = 'Health'; break; case 'lang'; $value_to_find = 'Foreign'; break; case 'comp'; $value_to_find = 'Computer'; break; case 'busin'; $value_to_find = 'Business'; break; case 'oth'; $value_to_find = 'Other'; break; } $query_title = mysql_query("SELECT l.title, l.id, l.image, l.search_text, lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height FROM listings l JOIN listings_urls lu ON lu.listing_id = l.id WHERE search_text LIKE '%$value_to_find%' AND live = 1"); $num = mysql_num_rows($query_title); if($num > 0) { echo "<table>"; while ($fetch = mysql_fetch_array($query_title) ) { if($fetch['image'] > 0) { if($fetch['thumb_url'] == 0) { $thumb_url = "images/".$fetch['full_filename']."'"; $width = $fetch['image_width']; $height = $fetch['image_height']; } else { $thumb_url = "images/".$fetch['thumb_url']."'"; $width = $fetch['image_width'] ; $height = $fetch['image_height'] ; } } else { $thumb_url = 'images/nopic.gif'; } echo "<tr>"; echo "<td>".$fetch['title']."</td>"; echo "<td><img src='http://mysite.com/$thumb_url' width='$width' height='$height'></td>"; echo "</tr>"; } } else { echo "no subject found!"; } ?> *****also...the footer appears when it echos "no subject found!" Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752085 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 It seems the query that you run returned no result. you might want to fix that by breaking down those SQL into different parts and try them 1 by 1. Hope it helps. Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752090 Share on other sites More sharing options...
peranha Posted February 1, 2009 Share Posted February 1, 2009 add or die(mysql_error()) to the end of your queries when testing. $query_title = mysql_query("SELECT l.title, l.id, l.image, l.search_text, lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height FROM listings l JOIN listings_urls lu ON lu.listing_id = l.id WHERE search_text LIKE '%$value_to_find%' AND live = 1") or die(mysql_error()); see if that helps Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752093 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 hey guys, thanks for the reply @Lucky_PHP_MAN i thingk its not understanding wat i want it to do.......if you look at my first post (topic start) i had a two queries run..like you suggest......one that called the table and one in the WHILE brackets {}.........it worked correctly and return results but my footer would go away.....not sure how i can tell it the exact fields im talkin about in the new query that i used JOIN @peranha i added the die(mysql_error()) and i dont recieve any errors.....still brings up "no subject found!" Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752106 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 Let me break down the ur query here and see whether the logic of the query is there $query_title = mysql_query("SELECT l.title, l.id, l.image, l.search_text, lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height FROM listings l JOIN listings_urls lu ON lu.listing_id = l.id WHERE search_text LIKE '%$value_to_find%' AND live = 1") or die(mysql_error()); 1st part SELECT l.title, l.id, l.image, l.search_text (you wanted to get the title, id, image, search text FROM listings table) 2nd part lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height (you wanted to get the thumb_url, full_filename, listing_id, image_width, image_height FROM listings_url table) 3rd part listings l JOIN listing_urls lu (joining the 2 tables in when query is run) 4th part ON lu.listing_id = l.id (Condition on JOIN => lu.listings_id matches l.id) 5th part WHERE search_text LIKE '%$value_to_find%' AND live = 1 (another condition "search_text" LIKE '$value_to_find' AND live is 1) I was wondering where u can use JOIN, ON, "and" WHERE together. That's just my guess. Maybe you might want to take off the WHERE condition to see whether you query has results in it. Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752110 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 Let me break down the ur query here and see whether the logic of the query is there $query_title = mysql_query("SELECT l.title, l.id, l.image, l.search_text, lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height FROM listings l JOIN listings_urls lu ON lu.listing_id = l.id WHERE search_text LIKE '%$value_to_find%' AND live = 1") or die(mysql_error()); 1st part SELECT l.title, l.id, l.image, l.search_text (you wanted to get the title, id, image, search text FROM listings table) 2nd part lu.thumb_url, lu.full_filename, lu.listing_id, lu.image_width, lu.image_height (you wanted to get the thumb_url, full_filename, listing_id, image_width, image_height FROM listings_url table) 3rd part listings l JOIN listing_urls lu (joining the 2 tables in when query is run) 4th part ON lu.listing_id = l.id (Condition on JOIN => lu.listings_id matches l.id) 5th part WHERE search_text LIKE '%$value_to_find%' AND live = 1 (another condition "search_text" LIKE '$value_to_find' AND live is 1) I was wondering where u can use JOIN, ON, "and" WHERE together. That's just my guess. Maybe you might want to take off the WHERE condition to see whether you query has results in it. Regards, LPM very well put my only issue is here:. 4th part ON lu.listing_id = l.id (Condition on JOIN => lu.listings_id matches l.id) see its only displaying listings that match this critirea....which are listings that have images...but there are other listings that don't have images and are live = 1...when they dont have images they dont have a listings_id in the listings_urls table (which is why its not displaying them)......so how can i get it to display both listings with images (and call the thumb_url to display the image in the listings_urls table) as well as display listings that dont have images (where the "img src=" would just end with nopic.jpb) Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752126 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 I hope I assumed correctly that you were just trying to list out everything basically whether it has images or no images, if so my solution would be. 1. Take off the "lu.listings_id = l.id" statement. 2. Modify the column inside your DB table which is "thumb_url" in this case to "nopic.jpg" or 3. You might want to let PHP do some checking. IF (thumb_url is empty) img src=nopic.jpg ELSE img src=somepic.jpg Hope this helps Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752130 Share on other sites More sharing options...
corbin Posted February 1, 2009 Share Posted February 1, 2009 Or, you could just change "JOIN" to "LEFT JOIN". Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752146 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 I hope I assumed correctly that you were just trying to list out everything basically whether it has images or no images, if so my solution would be. 1. Take off the "lu.listings_id = l.id" statement. 2. Modify the column inside your DB table which is "thumb_url" in this case to "nopic.jpg" or 3. You might want to let PHP do some checking. IF (thumb_url is empty) img src=nopic.jpg ELSE img src=somepic.jpg Hope this helps Regards, LPM i understand what you are trying to do but it wont work because....listings table specifies whether an ad(listing) has an image or not...its field is called image in the db so if (image ==1) i would make it display the image that corresponds with the listings_id in the url table (which stores the location of the image i.e. /images/ad#2123.jpg) and if its not equal to 1 it would display "nopic.jpg" but my main issue is the footer disappearing when the query is run......i cant figure out why it would disappear.....is it possible that the query is cut of at the end and wouldnt display the foot? Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752151 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 I'm not sure why your footer would not appear. It would be some of the "die()" method in PHP that makes is stop from intepreting the script. That could have stopped your footer from appearing. Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752153 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 its really weird...............i just opened the page source and the html has the footer in it......down to the location of the images in the footer.....everything exact.......but it wont display on the page itself....does that mean anything? Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752156 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 Maybe you can show a segment of the code that show the whole HTML page with its footer? that will helps a lot Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752158 Share on other sites More sharing options...
jeger003 Posted February 1, 2009 Author Share Posted February 1, 2009 sure here is the code for the footer that displays in page source.........but doesn't display on actual page. <!-- BEGIN FOOTER --> <table width="100%" border="0" cellpadding="4" cellspacing="0"> <tr valign="top"> <th align="left" class="FooterBkgrd" scope="col"> <table width="100%" height="100%" border="0" cellpadding="10" cellspacing="1"> <tr> <td width="100%" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="500" align="center"> <table width="220" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="footer_links" width="48" align="center"><a href="index.php" class="footer_links">home</a></td> <td width="1"><img src="images/footer_separator.gif" width="1" height="14"></td> <td class="footer_links" width="57" align="center"><a href="index.php?a=17" class="footer_links">logout</a></td> <td width="1"><img src="images/footer_separator.gif" width="1" height="14"></td> <td class="footer_links" width="54" align="center"><a href="index.php?a=28&b=141" class="footer_links">Help</a></td> <td width="1"><img src="images/footer_separator.gif" width="1" height="14"></td> <td class="footer_links" width="170" align="center"><a href="index.php?a=28&b=140" class="footer_links">Terms of Use</a></td> </tr> </table> </td> <td width="260" align="right"><img src="images/logo_ftr.gif" width="250" height="35"></td> </tr> <tr> <td width="500" align="center"> </td> <td width="260" align="right"> </td> </tr> </table><br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center" class="footer_text"> All Rights Reserved 2008<p><p><p><br></td> </tr> </table> </td> </tr> </table> </th> </tr> </table> <!-- END FOOTER --> Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752163 Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 The footer html looks fine with me. Could it be that you've attached some CSS that makes it all white? Regards, LPM Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752197 Share on other sites More sharing options...
Zane Posted February 1, 2009 Share Posted February 1, 2009 I noticed that in your PHP you haven't closed your table tag This could have everything to do with your footer disappearing. Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752204 Share on other sites More sharing options...
jeger003 Posted February 2, 2009 Author Share Posted February 2, 2009 @zanus OMG! OMG! its working.........HOW IN THE WORLD DO YOU CATCH SOMETHING LIKE THAT!!!.....we've been at it all day!! haha......THANKS SOO MUCH DUDE!! @Lucky_PHP_MAN hey THANKS SOO MUCH for you help man....had it not been for you i would have given up on it a long time ago........thanks for all your help!!! YOU GUYS ARE "FREAK"N AWESOME!!! Quote Link to comment https://forums.phpfreaks.com/topic/143375-solved-why-does-my-footer-go-away-when-this-query-is-run/#findComment-752262 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.