Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2005, 06:35 PM
Authorized User
 
Join Date: Mar 2005
Location: arima, West Indies, Trinidad and Tobago.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to arimakidd
Default Need This Explained

I am studying php/mysql. I am migrating from asp/access combination. The code below is fairly simple and its just one part giving me problems to understand. That is the while loop. I do not understand the condition. Before the loop starts what is the value of $row and what is the value of mysql_fetch_array($results). Here is the code:

Code:
<?php
//connect to MYSQL
$connect = mysql_connect("localhost","root","newman$")
or die("Hey loser, check your server connection.");

//make sure we're using the right database
mysql_select_db("moviesite");

$query = "SELECT movie_name, movie_type " .
"FROM movie " .
"WHERE movie_year>1990 ".
"ORDER BY movie_type";
$results = mysql_query($query)
or die(mysql_error());



while ($row = mysql_fetch_array($results)) {
extract($row);
echo $movie_name;
echo " _ ";
echo $movie_type;
echo "<br>";
}

?>
I hope I can get some kind of help here.

 
Old October 21st, 2005, 12:25 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

Before the loop starts what is the value of $row and what is the value of mysql_fetch_array($results).

Its fairly simple.

$row is nothing as not initialized before the loop.
$results points to {result set} of query to MySQL. It's an identifier.

while ($row = mysql_fetch_array($results)) says if $row is empty or if can't fetch an array from result set, exit from the loop.

`~@#\^%&*/\.<.\/-|+|_!:;..=?>
Support Indian students' finances http://scholarship.mediasworks.com/
 
Old November 3rd, 2005, 10:11 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

PHP unlike most programming languages don't require you to initialize a variable. It auto initializes the variable when you first use it. As is the case in your code. Foxpro used to allow the same type of stuff to make things easier for lazy programmers. It can sometimes be dangerous to do this though.





Similar Threads
Thread Thread Starter Forum Replies Last Post
EX9_03.CPP "bug" found/explained Matthew Doucette BOOK: Beginning Visual C++ 6 0 April 8th, 2005 10:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.