9 Replies - 2948 Views - Last Post: 02 May 2011 - 05:05 PM Rate Topic: -----

#1 cornetto456  Icon User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 438
  • Joined: 03-January 11

While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 03:11 AM

Hi ,

im making a website and im trying to implement a news system where the news is out the database so im making a while loop

and this is what i got :
    <?php
		$news = "SELECT nieuws FROM soccervision";
		
		$row = mysql_fetch_assoc($news);
		
		while($row == mysql_fetch_array($news ,$news){
			
		}
	
			
		?>


so if searchd a bit and then found to get multiple data from a database (in php) to use a while loop is this correct ?


dreamweaver says that i got a syntax error



Any body idea's ?



Thanks ;)

Is This A Good Question/Topic? 0
  • +

Replies To: While loop error when trying to get multiple data out the database

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 03:41 AM

Check this line :
while($row == mysql_fetch_array($news ,$news)


You want to store the value returned by mysql_fetch_array() into $row. SO you need an assignment operator there.
Was This Post Helpful? 1
  • +
  • -

#3 cornetto456  Icon User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 438
  • Joined: 03-January 11

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 03:48 AM

View Postchinchang, on 11 April 2011 - 03:41 AM, said:

Check this line :
while($row == mysql_fetch_array($news ,$news)


You want to store the value returned by mysql_fetch_array() into $row. SO you need an assignment operator there.

Oke but im sorry for this noobie question but what to do with that operator ?



Thanks
Was This Post Helpful? 0
  • +
  • -

#4 justforgetme  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 28
  • Joined: 05-September 09

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 05:31 AM

while($row == mysql_fetch_array($news ,$news))

means that you compare the value of $row to the return value (array) of command mysql_fetch_array($news ,$news).

what you want to do is to assign the return value of the command to the variable $row not compare it. in php and many other languages = is an assignment operator it translates to put the value of what's right of me into the container that is right of me

$container = function($that, $returns, $value);


whereas == compares the content of two containers (variables)

so what you want is use = not ==


while($row = mysql_fetch_array($news ,$news){
// do stuff
} 

Was This Post Helpful? 1
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,261
  • Joined: 08-June 10

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 05:44 AM

if you're having such a question, you should familiarise with PHP’s operators first.
Was This Post Helpful? 1
  • +
  • -

#6 cornetto456  Icon User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 438
  • Joined: 03-January 11

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 05:46 AM

View Postjustforgetme, on 11 April 2011 - 05:31 AM, said:

while($row == mysql_fetch_array($news ,$news))

means that you compare the value of $row to the return value (array) of command mysql_fetch_array($news ,$news).

what you want to do is to assign the return value of the command to the variable $row not compare it. in php and many other languages = is an assignment operator it translates to put the value of what's right of me into the container that is right of me

$container = function($that, $returns, $value);


whereas == compares the content of two containers (variables)

so what you want is use = not ==


while($row = mysql_fetch_array($news ,$news){
// do stuff
} 

Still getting an syntax error with dreamweaver code :
here ->	while($row = mysql_fetch_array($news , $news ) {
			
			echo $news;
		}


Thanks ;)

This post has been edited by cornetto456: 11 April 2011 - 05:46 AM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 05:48 AM

How about reading a tutorial?
Was This Post Helpful? 1
  • +
  • -

#8 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: While loop error when trying to get multiple data out the database

Posted 11 April 2011 - 09:50 AM

You should be using mysqli or PDO.

<?php
$mysqli = new mysqli("localhost", "username", "password", "database");
// Get our news. Order by desc() will return our latest news first.
$result = $mysqli->query("select * from news order by desc()");
while($news = $result->fetch_object()){
echo $news->title . "<br />";
echo $news->content . "<br />";
}
?>



I believe this code is valid? I'm having a hard time remembering at the moment.
Was This Post Helpful? 0
  • +
  • -

#9 justforgetme  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 28
  • Joined: 05-September 09

Re: While loop error when trying to get multiple data out the database

Posted 02 May 2011 - 03:50 PM

why would anybody use dw to write php?
Was This Post Helpful? 0
  • +
  • -

#10 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: While loop error when trying to get multiple data out the database

Posted 02 May 2011 - 05:05 PM

View Postcornetto456, on 11 April 2011 - 06:46 AM, said:

View Postjustforgetme, on 11 April 2011 - 05:31 AM, said:

while($row == mysql_fetch_array($news ,$news))

means that you compare the value of $row to the return value (array) of command mysql_fetch_array($news ,$news).

what you want to do is to assign the return value of the command to the variable $row not compare it. in php and many other languages = is an assignment operator it translates to put the value of what's right of me into the container that is right of me

$container = function($that, $returns, $value);


whereas == compares the content of two containers (variables)

so what you want is use = not ==


while($row = mysql_fetch_array($news ,$news){
// do stuff
} 

Still getting an syntax error with dreamweaver code :
here ->	while($row = mysql_fetch_array($news , $news ) {
			
			echo $news;
		}


Thanks ;)


You're missing an ) at the line with the while.


View Postjustforgetme, on 02 May 2011 - 04:50 PM, said:

why would anybody use dw to write php?


Please don't bump. I used DW for a bit, it's not that bad.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1