PDA

View Full Version : simple question


Dimava
Wed 29th May '02, 12:17am
$result = "SELECT catgroup FROM tutorials WHERE id=32";
mysql_query($result);
print $catgroup;


how can I define the variable $catrgoup to equal the thing that it pulled out from that database, because with the code above $catgroup is equal to nothing, but i just check with phpmyadmin, and there is something in that cell

thanks

Dimava

Mark Hensler
Wed 29th May '02, 2:18am
$result = "SELECT catgroup FROM tutorials WHERE id=32";
mysql_query($result);
extract(mysql_fetch_array($result, MYSQL_ASSOC));
print $catgroup;

Dimava
Wed 29th May '02, 7:19am
Warning: Undefined variable: catgroup in /home/virtual/site3/fst/var/www/html/admins/tutorials_remove.php on line 35
cat is


line 35 contains:
extract(mysql_fetch_array($result, MYSQL_ASSOC));


thanks

-Dimava

megahard
Wed 29th May '02, 8:36am
Undefined variable: catgroup

i think we can safely assume:

print $catgroup;

is line 35 seeming as you havent defined it and it matches up with what the error is complaing about.

megahard
Wed 29th May '02, 8:46am
this is how I do it, of course you can seperate each function if you want, but i usually just use a class to do all the work:


$result = mysql_fetch_array(mysql_query("SELECT catgroup FROM tutorials WHERE id=32"));
echo $result[0] . " This is the same as " . $result[catgroup];

scoutt
Wed 29th May '02, 12:14pm
I didn't know $result[0] worked in that way, cool :)

or simply put


$search = mysql_query("SELECT catgroup FROM tutorials WHERE id=32");

while($row = mysql_fetch_array($search)){
echo $result[catgroup];

}

Dan615
Wed 29th May '02, 7:31pm
$result = mysql_query("SELECT catgroup FROM tutorials WHERE id = 32");

$tutorial = mysql_fetch_array($result);

echo "$tutorial[catgroup]";



Echos one row, or


$result = mysql_query("SELECT catgroup FROM tutorials WHERE id = 32");

while ($tutorial = mysql_fetch_array($result)) {
echo "$tutorial[catgroup]";
}


Echos all of them :)

Dimava
Wed 29th May '02, 8:10pm
ok, thanks for your help guys