I implemented a simple bit of code, to randomly pick 2 ads from a mysql database and display them in the left hand column of my pages. The filed in mysql where the HTML is stored is of Type VARCHAR. To date I've had no problems with it. Then I joined Google's adsense and when I try to put the Google HTML into the database it doesn't seem to work. I think that the problem is that I am taking the linefeeds out before I stuff the html into the database. I'm using phpMyAdmin to put records into the database. I assumed that VARCHAR would not support newlines because I get a single line to put the field data into. However, a friend calaims VARCHAR will support newline characters.
My questions are:
Will VARCHAR allow me to have newline characters in it or do I need a different datatype (if so which)?
Will phpMyAdmin allow me to input data into a field with newlines and if so how?
Can anybody think of why if I strip linefeeds out of google's html code and replace it with spaces the html wouldn't work? - I thought javascript treated all whitespace the same.
The script can be seen in action at http://guidetosellingabusiness.com
The code that displays the ads is here:
<? for ($i=1 ; $i<=$numads; $i++){
if ($advs[$i-1]){
echo ' <tr>
<td class="btad">
<div align="Center">'.$advs[$i-1].'
</div>
</td>
</tr>';}
else {
$result = mysql_query("SELECT * FROM ads");
$num_rows = mysql_num_rows($result);
$whichone = rand(1,$num_rows);
$row_pointer = $whichone - 1 ; // rows start at 0, not one
if (!mysql_data_seek($result, $row_pointer)) {
echo "Cannot seek to row $row_pointer: " . mysql_error() . "\n";
continue;
}
if (!($row = mysql_fetch_assoc($result))) {
continue;
}
echo ' <tr>
<td class="btad"><div align="Center">'.$row['adhtml'].'
</div>
</td>
</tr>';
}
}
if ($specialbot){echo '<TR><TD>'.$specialbot.'</TD></TR>';}
?>
Thanks,
David
http://ignoranceoffsets.com
The gift for those with everything, except a clue