Jump to content

[SOLVED] why does my footer go away when this query is run?


jeger003

Recommended Posts

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!";
  }
?>


Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!"

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 -->

Link to comment
Share on other sites

@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!!!

 

 

 

 

 

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.