Page 1 of 1

problem with getting data from database

Posted: Fri Jun 03, 2005 10:43 am
by nutstretch
I am having problems I have a database which I am trying to get data from. I seem to be opening this with the sql database as I am not getting an error message and if i change the sql statement i do. my problem is that is is not reading the data for me and displaying it. The code is:

Code: Select all

<?php 
$name = $_POST['swimmer'];
$linkID = @mysql_connect("localhost", "root", "");
mysql_select_db("lpsc", $linkID);
//	$linkID = @mysql_connect("localhost", "astokes3","beebo1");
//mysql_select_db("leicester-penguins_co_uk_-_register", $linkID);
$sql ="select * from tblpbs where Name = '$name'";
$resultID = mysql_query($sql, $linkID)or die(mysql_error());
if(mysql_num_rows($resultID) < 1) 
{
print "Sorry Swimmer not recognised.<p>";
}
else
{
Print "<font color='#CC0033' size='2' face='Arial, Helvetica, sans-serif' align='centre'><strong>Personal Best times for $name </strong></font>";
 print "<table width='100%' border=1  bordercolor='$border'  align = 'center'   font color='$font'><tr><th><font color='#006666' face='Arial, Helvetica, sans-serif'>Distance</th> <th><font color='#006666' face='Arial, Helvetica, sans-serif'>Freestyle</th><th><font color='#006666' face='Arial, Helvetica, sans-serif'>Backstroke</th><th><font color='#006666' face='Arial, Helvetica, sans-serif'>Breastroke</th><th><font color='#006666' face='Arial, Helvetica, sans-serif'>Butterfly</th><th><font color='#006666' face='Arial, Helvetica, sans-serif'>Individual Medley</th>";
while ($row = mysql_fetch_assoc($resultID)) 
print "<tr align='center' bgcolor='#ffffff'>"; 
{ 
print "<td>25m</td>
print "<td>$row['25mfs']."</td>"; 
print "<td>".$row['25mbs']."</td>";

}
print "</table>";
}
mysql_close($linkID);
?>
Any help appreciated as getting very frustrated here.

Posted: Fri Jun 03, 2005 10:50 am
by Burrito
please use php tags when posting php code.

you say that when you change the query you DO get results? If that's the case, maybe your where clause is causing it to not find any results.

syntactically, everything looks fine (from what I could decipher).

are you getting your "sorry simmer not recognized" alert when it doesn't find anythign?

Posted: Fri Jun 03, 2005 11:05 am
by nutstretch
yes i am If i change the field it should be looking for to something else it says swimmer not there etc

Posted: Fri Jun 03, 2005 12:14 pm
by Burrito
ok now that you've added the php tags I see a few issues, but they're not query related:

1) your first print() line is not within your while loop
2) you're missing a closing quote and semi-colon on line 20

as for it not finding any rows in the db, I'd suggest you echo out the swimmer's name from the post var and try running your query with phpMyAdmin or from the command line to see if you can return any rows that way. If you do, then perhaps you're query isn't being created correctly within php so try echoing that out to see how it looks.

another thing to note, you need to make sure that your field names are spelled (case sensitive) the same as they are in the db. I noticed you have "where Name = '$name'";. that would probably throw an error if it couldn't find it, but somethign to consider...

Posted: Fri Jun 03, 2005 2:49 pm
by nutstretch
Thanks. It was the liine not in the while loop that was playing it up!. Thank you for all your other comments as well though

Angie