Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2015 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Mysql error (mysql_fetch_array doesn't work?)

Thread title: Mysql error (mysql_fetch_array doesn't work?)
Reply    
    Thread tools Search this thread Display Modes  
09-30-2009, 08:14 PM
#1
Patrick is offline Patrick
Status: I love this place
Join date: Apr 2007
Location: Chi-Town
Expertise: Java/C#/C++ Programmer
Software:
 
Posts: 543
iTrader: 5 / 100%
 

Patrick is an unknown quantity at this point

  Old

Change:

Code:
$result = mysql_query($sql, $connection);
To:

Code:
$res = mysql_query($sql, $connection);
And:

Code:
while ($myRow = mysql_fetch_array($result)) {
To:

Code:
while ($myRow = mysql_fetch_array($res)) {

Reply With Quote
09-30-2009, 08:30 PM
#2
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

Originally Posted by Patrick View Post
Change:

Code:
$result = mysql_query($sql, $connection);
To:

Code:
$res = mysql_query($sql, $connection);
And:

Code:
while ($myRow = mysql_fetch_array($result)) {
To:

Code:
while ($myRow = mysql_fetch_array($res)) {
Erm, that won't achieve anything...

Anyway, here's a version that's fixed in various places, and has some minor code changes that I'd personally consider more best practices.
PHP Code:
<html>
<head>
<title>Lab 4</title>
</head>
<body>
<?
$connection 
mysql_connect("HOST_HERE""USER_HERE""PASSWORD_HERE") or die ("Kunde inte an****a!");

mysql_select_db("DB_NAME_HERE"$connection);

$input $_POST['revealThis'];

if (
$input == 'debattartiklar') {
    
$sql "SELECT * FROM debatt";
} elseif (
$input == 'eva') {
    
$sql "SELECT * FROM debatt, sports WHERE forfattare='Eva Svensson'";
} else {
    echo 
"Du valde inget alternativ, vänligen välj ett";
}
    
$result mysql_query($sql$connection);

while (
$myRow mysql_fetch_assoc($result)) {
        echo 
"<h3 style=\"line-height:1.5em; margin:0; padding:0;\">{$myRow['rubrik']}</h3>";
        echo 
"<strong>{$myRow['ingress']}</strong><br />";
        echo 
"{$myRow['brodtext']}<br />";
        echo 
"{$myRow['forfattare']}{$myRow['datum']}<br /><br />";
}

mysql_close($connection);

?>
</body>
</html>
Also take a look into mysqli instead of mysql.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed