
January 4th, 2004
07:09 PM
quick code check
Can't seem to figure out what is causing an error here.
<?php
$user = "****";
$pass = "****";
$db = "***";
$link = mysql_connect("localhost", "$user", "$pass");
if (! $link)
die ("couldn't connect to MySQL");
mysql_select_db($db, $link) or die ("couldn't open $db: ".mysql_error());
$result = mysql_query("SELECT * FROM myDB WHERE id=1");
$a_row = mysql_fetch_array($result);
$num_rows =mysql_num_rows($result);
print "$num_rows Rows \n "; //prints 1 Rows
print $a_row; // prints Array
//each of these below cause an error
foreach($a_row as $key => $value) {
print $key.$value;
}
while ($a_row) {
print("yes");
}
?>
Last edited by killrobotkill, January 4th, 2004 07:45 PM (Edited 1 times)

January 4th, 2004
07:48 PM
my biography
Status: Offline!

January 4th, 2004
08:14 PM
Yeah, must have fixed it when you were typing....anyways I was messing around with the while loops and ran into some problems......I am still confused about this.
This crashes my browser:
<?php
$a_row = mysql_fetch_array($result);
while ($a_row){
print "yes";
}
?>
This works:
<?php
while($a_row = mysql_fetch_array($result){
print "yes";
}
?>
I don't understand why the second crashes my browser.
Is it because the loop is just checking the variable of $a_row, and not the statement of $a_row = mysql_fetch_array($result)

January 4th, 2004
10:59 PM
my biography
Status: Offline!
if($a_row){
print "yes";
}
if youre checking the var
while($a_row = mysql_fetch_array($result){
print "yes";
}
if you want to print yes for every result
___________________
Infinite Fire - Photoshop, PHP, HTML, CSS and Webmaster Tutorials - Web Design Centre
Photoshop Tutorials | PHP Tutorials | HTML Tutorials | Webmaster Tips and Tricks
Buy Cheap Digital Cameras!