PHP and MySQL help needed!

Delltron

Limp Gawd
Joined
Mar 20, 2002
Messages
173
Hi guys, im working on a new site and im trying to input data from a mysql database that I set up. For some reason, I am not able to get data from Row 1?? Im new to coding, so not sure what it could be. Heres the code:

<?php
$db_host = 'localhost';
$db_name = 'sfpubcra_pub';
$db_user = 'sfpubcra_pub';
$db_pass = 'admin';
$pconn = 'off';

if($pconn == 'off') {
$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
} else {
$db = mysql_pconnect($db_host, $db_user, $db_pass) or die(mysql_error());
}

mysql_select_db($db_name, $db);

$sql = "SELECT * FROM sfpubcra_pub.sfpubs";
$result = @mysql_query($sql,$db) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
$name =$row['1'];
$url =$row['11'];
echo "var point = new GPoint(".$row['8'].",".$row['9'].");\n";
echo "var marker = createMarker(point, '<div id=\"infowindow\" style=\"white-space: nowrap;\">".$row['1']."<br />".$url."<br />".$row['10']."</div>');\n";
echo "map.addOverlay(marker);\n";
echo "\n";
}
?>

So this returns the 8th and 9th rows successfully, but the $row['1'] shows up blank? in the html output from the php page it shows the field correctly, but its not displaying on the page.
 
Delltron said:
So this returns the 8th and 9th rows successfully, but the $row['1'] shows up blank? in the html output from the php page it shows the field correctly, but its not displaying on the page.

Just to make sure I'm understanding this correctly: Do you mean that the surrounding HTML is output correctly but not the field data, or that it shows up in the HTML but not when you view the page?
(You're asking for help with the former, but it really sounds like you're describing the latter.)

Anyway. A good place to start is by adding a bit of debugging code. Instead of the while loop you have, try this:
Code:
echo "<pre>";
while ($row=mysql_fetch_assoc($result)) print_r($row);
echo "</pre>\n";
If everything shows up as expected, replace the mysql_fetch_assoc with mysql_fetch_array to see if the field numbers you use seem to fit. (Or just use _assoc and field names. It's easier to read and more robust to changes in the query or DB.)
 
I am describing the latter, when I view the page source it is in the html, but doesnt show up on the page. Ill try that out! THanks
 
Actually, that means that you do get the data correctly, and the problem is in the HTML/formatting instead of the PHP. :)
 
Delltron said:
it was actually a piece of data in the db. but its fixed! thanks!
Did it contain something that borked the HTML, or?
(Just curious.)
 
Back
Top