Jump to content

Need to add adsense to the results pages...Please help.


ineedhelp512

Recommended Posts

Hi everyone,

This is the first time that i am here. I am working on a project that will act as a business directory. Now the search results page script works just fine without adsense but when i add adsense it give me unexpected T should be "," or ";" something.....so here is my code, PLEASE HELP I tried so much but could not......... Lets see how PHP Freaks you guys actually are

 

 

<?php

$pageTitle='Your Search Results';

include("header_query.php");

?>

<body OnLoad="loadImages()">

<!-- LOADING PAGE -->

<div id="hidepage" style="position: absolute; left:0px; top:225px; height: 100%; width: 100%;">

 

<table width=100% height=100%><tr><td align='center' valign='center'>

<object width="225" height="200">

<param name="movie" value="nationwideloading.swf">

<embed src="images/something.swf" width="500" height="200">

</embed>

</object>

</td></tr></table></div>

<!-- LOADING PAGE -->

 

<?php

include("ps_pagination.php");

//set db server access variables

$host = "something";

$user = "something";

$pass = "something";

$db = "something";

 

//open connection

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

 

//select database

mysql_select_db($db) or die ("Unable to select database!");

 

//create query

//if(!isset($name)){

$name = $_GET["name"];

//}

 

//if(!isset($category)){

$category = $_GET["category"];

//}

 

//if(!isset($city)){

$city = $_GET["city"];

//}

 

//if(!isset($state)){

$state = $_GET["state"];

//}

 

if ($state == "NW") {

        $state="";

}

 

if(strlen($city) == 0){

$cityQuery = "";

}else{

$cityQuery = "and `city` = '$city' ";

}

if(strlen($state) == 0){

        $stateQuery = "";

}else{

        $stateQuery = "and `state` = '$state' ";

}

 

if (strlen($category) == 0) {

        $type="`name` LIKE '".$name."%'";

}

if (strlen($name) == 0) {

        $type="`description` LIKE '%".$category."%'";

}

 

/*

if (strlen($city) == 0) {

        $cityQuery = "";

} else {

        $cityQuery = "and city = '$city'";

}

 

if ($state == "NW") {

        $stateQuery = "";

} else {

        $stateQuery = "and state = '$state'";

}

*/

/*

if(!isset($_GET['query'])){ {

if( strlen($category) == 0 ){

        $query = "SELECT * FROM clients WHERE name LIKE '$name%' $cityQuery $stateQuery";

}else if( strlen($name) == 0 ){

        $query = "SELECT * FROM clients2 WHERE description LIKE '%$category%' $cityQuery $stateQuery";

        //name=&category=&city=&state=

}

$query = $query ." ORDER BY name";

}*/

 

// $query creation

 

// Detetermine which table to use based on the selected state

$region2 = array("CO","IA","KS","MN","MO","MT","ND","NE","SD","UT","WI","WY","AR","AZ","LA","NM","OK","TX","AK","CA","HI","ID","NV","OR","WA");

 

if (array_search($state, $region2) == NULL)

  $dbtable = "clients";

else

  $dbtable = "clients9";

 

if(!isset($_GET['query'])){

        $query = "SELECT * FROM `clients` WHERE " . $type . " " . $cityQuery . " " .$stateQuery;

        $query = $query ." ORDER BY name";

}else{

        $query=$_GET['query'];

}       

 

if( strlen($category) == 0  && strlen($name) == 0 ){

        //$query = NULL;

}

 

// Pagination

 

// how many rows to show per page

$rowsPerPage = 15;

 

// by default we show first page

$pageNum = 1;

 

// if $_GET['page'] defined, use it as page number

if(isset($_GET['page']))

{

    $pageNum = $_GET['page'];

}

 

// counting the offset

$offset = ($pageNum - 1) * $rowsPerPage;

 

$pager = new PS_Pagination($connection, $query, 15, 10, $name, $category, $city, $state );

 

//execute query

//$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

$result = $pager->paginate();

$totalResults = $pager->getNumberOfResults();

$totalPages = $pager->getNumberOfPages();

 

//displaying results

echo "

<div id='header'>

        <!--<h1>YellowPages</h1>-->

        <table border='0' width='100%'>

        <tr><td align='left'>

        <span><img src='images/banner_logo.png' alt='' /></span>

        </td><td align='right'>

<span><img src='images/toll.gif' alt='' /></span>

        </td><td>  </td></tr></table>

</div>";

include("navigation.php");

echo "<div id='content'>

<div id='hspace'>

        <!-- horizontal space -->

</div>

<!-- horizontal space -->

<table border='0'  width='100%'>

<tr>

        <td width='200px' valign='center' align='center'>

        <img src='images/contact.png' width='225px' alt='' />

</td>

<td>

                <h2 class='title'>Number of businesses found: ".$totalResults." - Page ".$pageNum." of ".$totalPages."</h2>

                <div class='content'>";

 

                /*if( $query == NULL ){

                        echo "SEARCH ERROR MESSAGE";

                }else if ( strlen($city) == 0 && strlen($category) == 0 ){

                        echo "SEARCH ERROR MESSAGE CATEGORY";

                }*/

                //echo $query;

 

 

// see if any rows were returned

if (mysql_num_rows($result) > 0) {

    // yes

    // print them one after another

    echo "<table cellpadding=10 border=0 width=100% >";

    while($row = mysql_fetch_row($result)) {

        echo "<tr><td><b>";

        /*

        echo "<td>".$row[0]."</td>";

        echo "<td>".$row[1]."</td>";

        echo "<td>".$row[2]."</td>";

        echo "<td>".$row[3]."</td>";

        echo "<td>".$row[4]."</td>";

        echo "<td>".$row[11]."</td>";

        */

        echo $row[1]."</b><br/><br/>";

        echo $row[2].", <br/>";

        echo $row[3].", ". $row[4] . ", " .$row[5] ."<br />";

                $phone = $row[6];

                if(strlen($phone)!=0){

                $area = substr($phone, 0, 3);       

                $pre = substr($phone, 3, 3);

                $post = substr($phone, 6, 4);

        echo "Telephone: (" .$area.") ".$pre."-".$post. "<br />";

                }

                $fax = $row[8];

                if(strlen($fax)!=0){

                $farea = substr($fax, 0, 3);       

                $fpre = substr($fax, 3, 3);

                $fpost = substr($fax, 6, 4);

        echo "Fax: (" .$farea.") ".$fpre."-".$fpost. "<br />";

                }

                if(strlen($row[10])!=0){

        echo "Email: <a href='mailto:".$row[10]."'>".$row[10]." </a><br/>";

                }

                if(strlen($row[9])!=0){

        echo "Website: <a target='_blank' href='http://".$row[9]."'>".$row[9]."<br/>";

                }

        echo $row[11]."</b><br/><br/>";

        echo "

        <table border='0' cellpadding='5px' width='100%'><tr>

        <td valign='bottom' align='center'><a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'><img src='images/map_icon.png' alt='' /></a><br />

        <a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'>map</a>

        </td>

                <!--Business Homepage-->

        <td valign='bottom' align='center'>";

                if( strlen( $row[9] ) !=0 ){

                echo "<a target='_blank' href='http://".$row[9]."'><img src='images/home_icon.png' alt=''><br/> website

                </a>";}

                echo "</td>

        <!-- Email -->

        <td valign='bottom' align='center'>";

                if( strlen( $row[10] ) !=0 ){

                echo"<a href='mailto:".$row[10]."'><img src='images/email_icon.png' alt=''><br/>email

                </a>";}

                echo"</td>

        </tr></table>";

        echo "</td><td valign='center' align='center'>";

              echo "<br /><img src='images/logo-small.png' alt='' /><br/>";

              echo "<strong><a href=\"javascript:slogan('".$row[15]."')\">See Business Slogan</a></strong>";

        echo "</td></tr><tr><td colspan='2'><hr /></td></tr>";

    }

    echo "</table>";

        //-----------------

        // print the link to access each page

        echo $pager->renderFullNav();

 

}

else {

    // no

    // print status message

    echo "<img src='images/info.gif' alt='' />  We apologize, no somethingsomething.com listings matching your search criteria were found.<br /><br/>";

        echo "Please return to the <a href='index.php'>previous page</a> and re-enter correct or more search criteria.";

}

 

// free result set memory

mysql_free_result($result);

 

// close connection

mysql_close($connection);

 

echo  "</td></tr></table></div>";

include("footer.php");

?>

 

 

I want to add adsense after every result on the page. Please help me with this. Thank You

Link to comment
Share on other sites

Adsense is JS and not PHP, therefor your unexpected 'T-whatever' is caused by you closing the code and reopening it. You may want to use HEREDOC such as..

 

<?php
...
$adsense = <<<END
//Adsense code here
//All in normal HTML before end..
END;
echo $adsense;
?>

 

To work around any problems by splitting the code..

Link to comment
Share on other sites

after adding i got this

 

Parse error: syntax error, unexpected '<' in results.php on line 236

 

and this is what i did

 

 

// see if any rows were returned

if (mysql_num_rows($result) > 0) {

    // yes

    // print them one after another

    echo "<table cellpadding=10 border=0 width=100% >";

    while($row = mysql_fetch_row($result)) {

        echo "<tr><td><b>";

        /*

        echo "<td>".$row[0]."</td>";

        echo "<td>".$row[1]."</td>";

        echo "<td>".$row[2]."</td>";

        echo "<td>".$row[3]."</td>";

        echo "<td>".$row[4]."</td>";

        echo "<td>".$row[11]."</td>";

        */

        echo $row[1]."</b><br/><br/>";

        echo $row[2].", <br/>";

        echo $row[3].", ". $row[4] . ", " .$row[5] ."<br />";

                $phone = $row[6];

                if(strlen($phone)!=0){

                $area = substr($phone, 0, 3);       

                $pre = substr($phone, 3, 3);

                $post = substr($phone, 6, 4);

        echo "Telephone: (" .$area.") ".$pre."-".$post. "<br />";

                }

                $fax = $row[8];

                if(strlen($fax)!=0){

                $farea = substr($fax, 0, 3);       

                $fpre = substr($fax, 3, 3);

                $fpost = substr($fax, 6, 4);

        echo "Fax: (" .$farea.") ".$fpre."-".$fpost. "<br />";

                }

                if(strlen($row[10])!=0){

        echo "Email: <a href='mailto:".$row[10]."'>".$row[10]." </a><br/>";

                }

                if(strlen($row[9])!=0){

        echo "Website: <a target='_blank' href='http://".$row[9]."'>".$row[9]."<br/>";

                }

        echo $row[11]."</b><br/><br/>";

        echo "

        <table border='0' cellpadding='5px' width='100%'><tr>

        <td valign='bottom' align='center'><a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'><img src='images/map_icon.png' alt='' /></a><br />

        <a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'>map</a>

        </td>

                <!--Business Homepage-->

        <td valign='bottom' align='center'>";

                if( strlen( $row[9] ) !=0 ){

                echo "<a target='_blank' href='http://".$row[9]."'><img src='images/home_icon.png' alt=''><br/> website

                </a>";}

                echo "</td>

        <!-- Email -->

        <td valign='bottom' align='center'>";

                if( strlen( $row[10] ) !=0 ){

                echo"<a href='mailto:".$row[10]."'><img src='images/email_icon.png' alt=''><br/>email

                </a>";}

                echo"</td>

        </tr></table>";

        echo "</td><td valign='center' align='center'>";

              echo "<br /><img src='images/logo-small.png' alt='' /><br/>";

              echo "<strong><a href=\"javascript:slogan('".$row[15]."')\">See Business Slogan</a></strong>";

        echo "</td></tr><tr><td colspan='2'><hr /></td></tr>";

<?php

$adsense = <<<END

<script type="text/javascript"><!--

google_ad_client = "pub-453748975398479537";

/* 468x60, created 9/12/09*/

google_ad_slot = "437598734";

google_ad_width = 468;

google_ad_height = 60;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

END;

echo $adsense;

?>

    }

    echo "</table>";

        //-----------------

        // print the link to access each page

        echo $pager->renderFullNav();

 

and i got this error...... i am new so please show me an example

Link to comment
Share on other sites

see.... no one helps the new guy :'(

i gave the complete page code.... the adsense code and all the errors....

so can someone PLEASE actually see code... and add the google code in it after these lines......

 

<!-- Email -->

        <td valign='bottom' align='center'>";

                if( strlen( $row[10] ) !=0 ){

                echo"<a href='mailto:".$row[10]."'><img src='images/email_icon.png' alt=''><br/>email

                </a>";}

                echo"</td>

        </tr></table>";

 

and post it here.

Thanks in advance and help the new guy..... i dont understand your big words like markup and other stuff..... bottom line.... show me how to do it........ and that comes with PLEASE 10 times

Link to comment
Share on other sites

:'( PLEASE HELP FIX ANY ERRORS IN THE FOLLOWING SCRIPT AND HELP ME ADD ADSENSE TO THE CODE.

 

<?php
$pageTitle='Your Search Results';
include("header_query.php");
?>
<body OnLoad="loadImages()">
<!-- LOADING PAGE -->
<div id="hidepage" style="position: absolute; left:0px; top:225px; height: 100%; width: 100%;">

<table width=100% height=100%><tr><td align='center' valign='center'>
<object width="225" height="200">
<param name="movie" value="nationwideloading.swf">
<embed src="images/something.swf" width="500" height="200">
</embed>
</object>
</td></tr></table></div>
<!-- LOADING PAGE -->

<?php
include("ps_pagination.php");
//set db server access variables
$host = "something";
$user = "something";
$pass = "something";
$db = "something";

//open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

//select database
mysql_select_db($db) or die ("Unable to select database!");

//create query
//if(!isset($name)){
$name = $_GET["name"];
//}

//if(!isset($category)){
$category = $_GET["category"];
//}

//if(!isset($city)){
$city = $_GET["city"];
//}

//if(!isset($state)){
$state = $_GET["state"];
//}

if ($state == "NW") {
        $state="";
}

if(strlen($city) == 0){
$cityQuery = "";
}else{
$cityQuery = "and `city` = '$city' ";
}
if(strlen($state) == 0){
        $stateQuery = "";
}else{
        $stateQuery = "and `state` = '$state' ";
}

if (strlen($category) == 0) {
        $type="`name` LIKE '".$name."%'";
}
if (strlen($name) == 0) {
        $type="`description` LIKE '%".$category."%'";
}

/*
if (strlen($city) == 0) {
        $cityQuery = "";
} else {
        $cityQuery = "and city = '$city'";
}

if ($state == "NW") {
        $stateQuery = "";
} else {
        $stateQuery = "and state = '$state'";
}
*/
/*
if(!isset($_GET['query'])){ {
if( strlen($category) == 0 ){
        $query = "SELECT * FROM clients WHERE name LIKE '$name%' $cityQuery $stateQuery";
}else if( strlen($name) == 0 ){
        $query = "SELECT * FROM clients2 WHERE description LIKE '%$category%' $cityQuery $stateQuery";
        //name=&category=&city=&state=
}
$query = $query ." ORDER BY name";
}*/

// $query creation

// Detetermine which table to use based on the selected state
$region2 = array("CO","IA","KS","MN","MO","MT","ND","NE","SD","UT","WI","WY","AR","AZ","LA","NM","OK","TX","AK","CA","HI","ID","NV","OR","WA");

if (array_search($state, $region2) == NULL)
  $dbtable = "clients";
else
  $dbtable = "clients9";

if(!isset($_GET['query'])){
        $query = "SELECT * FROM `clients` WHERE " . $type . " " . $cityQuery . " " .$stateQuery;
        $query = $query ." ORDER BY name";
}else{
        $query=$_GET['query'];
}       

if( strlen($category) == 0  && strlen($name) == 0 ){
        //$query = NULL;
}

// Pagination

// how many rows to show per page
$rowsPerPage = 15;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$pager = new PS_Pagination($connection, $query, 15, 10, $name, $category, $city, $state );

//execute query
//$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$result = $pager->paginate();
$totalResults = $pager->getNumberOfResults();
$totalPages = $pager->getNumberOfPages();

//displaying results
echo "
<div id='header'>
        <!--<h1>YellowPages</h1>-->
        <table border='0' width='100%'>
        <tr><td align='left'>
        <span><img src='images/banner_logo.png' alt='' /></span>
        </td><td align='right'>
   <span><img src='images/toll.gif' alt='' /></span>
        </td><td>  </td></tr></table>
</div>";
include("navigation.php");
echo "<div id='content'>
<div id='hspace'>
        <!-- horizontal space -->
</div>
<!-- horizontal space -->
<table border='0'  width='100%'>
<tr>
        <td width='200px' valign='center' align='center'>
        <img src='images/contact.png' width='225px' alt='' />
   </td>
   <td>
                <h2 class='title'>Number of businesses found: ".$totalResults." - Page ".$pageNum." of ".$totalPages."</h2>
                <div class='content'>";

                /*if( $query == NULL ){
                        echo "SEARCH ERROR MESSAGE";
                }else if ( strlen($city) == 0 && strlen($category) == 0 ){
                        echo "SEARCH ERROR MESSAGE CATEGORY";
                }*/
                //echo $query;


// see if any rows were returned
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
    echo "<table cellpadding=10 border=0 width=100% >";
    while($row = mysql_fetch_row($result)) {
        echo "<tr><td><b>";
        /*
        echo "<td>".$row[0]."</td>";
        echo "<td>".$row[1]."</td>";
        echo "<td>".$row[2]."</td>";
        echo "<td>".$row[3]."</td>";
        echo "<td>".$row[4]."</td>";
        echo "<td>".$row[11]."</td>";
        */
        echo $row[1]."</b><br/><br/>";
        echo $row[2].", <br/>";
        echo $row[3].", ". $row[4] . ", " .$row[5] ."<br />";
                $phone = $row[6];
                if(strlen($phone)!=0){
                $area = substr($phone, 0, 3);       
                $pre = substr($phone, 3, 3);
                $post = substr($phone, 6, 4);
        echo "Telephone: (" .$area.") ".$pre."-".$post. "<br />";
                }
                $fax = $row[8];
                if(strlen($fax)!=0){
                $farea = substr($fax, 0, 3);       
                $fpre = substr($fax, 3, 3);
                $fpost = substr($fax, 6, 4);
        echo "Fax: (" .$farea.") ".$fpre."-".$fpost. "<br />";
                }
                if(strlen($row[10])!=0){
        echo "Email: <a href='mailto:".$row[10]."'>".$row[10]." </a><br/>";
                }
                if(strlen($row[9])!=0){
        echo "Website: <a target='_blank' href='http://".$row[9]."'>".$row[9]."<br/>";
                }
        echo $row[11]."</b><br/><br/>";
        echo "
        <table border='0' cellpadding='5px' width='100%'><tr>
        <td valign='bottom' align='center'><a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'><img src='images/map_icon.png' alt='' /></a><br />
        <a target='_blank' href='http://www.mapquest.com/maps/map.adp?address=". $row[2] ."&city=".$row[3]."&state=".$row[4]."&country=us&cid=lfmaplink'>map</a>
        </td>
                <!--Business Homepage-->
        <td valign='bottom' align='center'>";
                if( strlen( $row[9] ) !=0 ){
                echo "<a target='_blank' href='http://".$row[9]."'><img src='images/home_icon.png' alt=''><br/> website
                </a>";}
                echo "</td>
        <!-- Email -->
        <td valign='bottom' align='center'>";
                if( strlen( $row[10] ) !=0 ){
                echo"<a href='mailto:".$row[10]."'><img src='images/email_icon.png' alt=''><br/>email
                </a>";}
                echo"</td>
        </tr></table>";
        echo "</td><td valign='center' align='center'>";
               echo "<br /><img src='images/logo-small.png' alt='' /><br/>";
               echo "<strong><a href=\"javascript:slogan('".$row[15]."')\">See Business Slogan</a></strong>";
        echo "</td></tr><tr><td colspan='2'><hr /></td></tr>";
    }
    echo "</table>";
        //-----------------
        // print the link to access each page
        echo $pager->renderFullNav();

}
else {
    // no
    // print status message
    echo "<img src='images/info.gif' alt='' />   We apologize, no somethingsomething.com listings matching your search criteria were found.<br /><br/>";
        echo "Please return to the <a href='index.php'>previous page</a> and re-enter correct or more search criteria.";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);

echo  "</td></tr></table></div>";
include("footer.php");
?>

 

PLEASE HELP ME FIX ANY ERRORS IN THE CODE AND HELP ME ADD ADSENSE CODE AFTER THE FOLLOWING LINES.

<!-- Email -->
        <td valign='bottom' align='center'>";
                if( strlen( $row[10] ) !=0 ){
                echo"<a href='mailto:".$row[10]."'><img src='images/email_icon.png' alt=''><br/>email
                </a>";}
                echo"</td>
        </tr></table>";

Link to comment
Share on other sites

its not that no one will help you  - we have done so already.

 

If the parser is giving you an error then you need to be able to understand that information and act on it - that is something that you need to be able to do your self.

 

If you do't understand terms like 'markup' then you should really go and do a little more self teaching as that is fundamental.

 

People want to help - but we don't have the time to teach everything - you need to take some of that on yourself.

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.