mysql_fetch_Mistake!!

Codes here !

Moderators: macek, egami, gesf

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

mysql_fetch_Mistake!!

Postby php-punk » Mon Apr 28, 2003 1:34 pm

right, heya guys (or gals if the case maybe), i have compiled this code to return news from a DB, it is re-used codethat has worked before but is bringing up errors now..

CODE:

Code: Select all

<?PHP

$c = mysql_connect(localhost,"punk3dude","badger") or die ("Sorry unable to connect to the database at point 1".mysql_error());

$db = mysql_select_db(punk3dude_uk_db,$c);

$query = "SELECT * FROM news";

$result = mysql_query($query) or die("Sorry unable to connect to the database at point 2".mysql_error());


echo("<font color=\"#000000\" face="Geneva, Arial, Helvetica, san-serif"><b>Current News</b></font>");

while($row = mysql_fetch_array($result));
{
   echo(" ");
   echo("<table celpadding=\"1\" cellspacing=\"1\">");

   echo("<tr>");
   echo("<td bgcolor=\"#FF9C4A\"><font color=\"#FFFFFF\">".$row["news-name"]."</font></td>");
   echo("</tr>");

   echo("<tr>");
   echo("<td bgcolor=\"#FFE7C6\">".$row["news"]."</td>");
   echo("</tr>");
   }
   echo("</table>");
   
   mysql_free_result($result);
?>


anyone help!?

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Mon Apr 28, 2003 10:35 pm

what errors is it bring up?

Andrew

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Tue Apr 29, 2003 2:27 am

make sure your username/password are correct and makesure the table actually exists.

andrewdavey
New php-forum User
New php-forum User
Posts: 16
Joined: Wed Feb 12, 2003 5:27 am
Location: Cornwall, England

Missing escape on quotes

Postby andrewdavey » Tue Apr 29, 2003 6:38 am

You are missing the escape (\) on the double-quotes below:

Code: Select all

echo("<font color=\"#000000\" face="Geneva, Arial, Helvetica, san-serif"><b>Current News</b></font>");


should be

Code: Select all

echo("<font color=\"#000000\" face=\"Geneva, Arial, Helvetica, san-serif\"><b>Current News</b></font>");

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Tue Apr 29, 2003 6:58 am

o0o0o0o0o, well spotted! Hehe

Andrew

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

erm..

Postby php-punk » Tue Apr 29, 2003 9:55 am

well i have added the esape char for the quotes, now it will display the page (no errors) but it will not display the data from the mysql_Fetch_array, i havn't a clue in whats going on

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

Postby php-punk » Tue Apr 29, 2003 10:48 am

http://members.lycos.co.uk/punkprogrammer/db.gif - picture of PHPmyAdmin screen including tables

i have tired and tweaked with the array but it still does not want to display the data within the array!

can anyone help!?[/list]

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Tue Apr 29, 2003 1:13 pm

if you are going to name your table with a capital (News) then trying to access lowercase (news) is going to return zero results no matter how many rows you add to capital (News)

same with $row["news-name"] - if your colums are named 'id', 'date', 'title' and 'news' you are not going to get that variable holding much.

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Tue Apr 29, 2003 1:15 pm

subnote: do yourself a favour and remove your username and password from your first post - never a good idea to post things like that on a public forum, even if your space is from a free host.

php-punk
New php-forum User
New php-forum User
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk
Contact:

changed array

Postby php-punk » Wed Apr 30, 2003 1:46 am

right, i have changed the titles in the array to those in teh DB (i had done this already but forgot about changing original code!), but still i am getting no reults from the DB

Code: Select all


<?PHP

$c = mysql_connect(localhost,"***","***") or die ("Sorry unable to connect to the database at point 1".mysql_error());

$db = mysql_select_db(***,$c);

$query = "SELECT * FROM News";

$result = mysql_query($query) or die("Sorry unable to connect to the database at point 2".mysql_error());


echo("<font color=\"#000000\" face=\"Geneva, Arial, Helvetica, san-serif\"><b>The Goings on..</b></font>");

while ($row = mysql_fetch_array($result));
{
   echo(" ");
   echo("<table celpadding=\"1\" cellspacing=\"1\">");

   echo("<tr>");
   echo("<td bgcolor=#FF9C4A><font color=\"#FFFFFF\">".$row["title"]."</font></td>");
   echo("<td>".$row["title"]."</td>");
   echo("</tr>");

   echo("<tr>");
   echo("<td bgcolor=#FFE7C6>".$row["news"]."</td>");
   echo("</tr>");
   }
   echo("</table>");
   
   mysql_free_result($result);

?>


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests