Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

52 users online



quick code check

quick code check

Currently viewing this thread: 1 (0 members and 1 guests)


killrobotkill

killrobotkill

Status: Offline!

quick code check

Can't seem to figure out what is causing an error here.

PHP:

<?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)

Huscy

Huscy

my biography
Status: Offline!

foreach($a_row as $key => $value) {

print $key.' - '.$value;

}

ok youve edited it now :P

___________________

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!

killrobotkill

killrobotkill

Status: Offline!

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:

<?php
$a_row 
mysql_fetch_array($result);
while (
$a_row){
print 
"yes";
}
?>

This works:

PHP:

<?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)

Huscy

Huscy

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!

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0081 seconds.