PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
purephazer3
Forum Newbie
Posts: 6 Joined: Thu Mar 16, 2006 3:23 pm
Post
by purephazer3 » Mon Mar 20, 2006 1:52 pm
I have the following and I only get one echo to work
Code: Select all
<?php
function match_sample($id) {
INCLUDE('pconfig.php');
$query = "SELECT dinkcolor1, dinkcolor2, dlining, dmotif, dtypestyle1, dtypestyle2 FROM weddefault WHERE dsample = $id";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );
$selInkcolor1 = $row['dinkcolor1'];
$selInkcolor2 = $row['dinkcolor2'];
$selLining = $row['dlining'];
$selMotif = $row['dmotif'];
$selTypestyle1 = $row['dtypestyle1'];
$selTypestyle2 = $row['dtypestyle2'];
//this one works
echo ($selInkcolor1);
}
match_sample(4);
//this one doesn't why
echo ($selInkcolor1);
?>
Last edited by
purephazer3 on Mon Mar 20, 2006 3:08 pm, edited 3 times in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 20, 2006 1:54 pm
return the variable.
Code: Select all
...
return $selInkcolor1
}
$inkColor1 = match_sample(4);
echo $inkColor1;
purephazer3
Forum Newbie
Posts: 6 Joined: Thu Mar 16, 2006 3:23 pm
Post
by purephazer3 » Mon Mar 20, 2006 2:01 pm
ok, but what if i want to access all of those variables in the function. Is there a quick and easy way to do that?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 20, 2006 2:03 pm
return the array ($row)
purephazer3
Forum Newbie
Posts: 6 Joined: Thu Mar 16, 2006 3:23 pm
Post
by purephazer3 » Mon Mar 20, 2006 2:23 pm
sorry, darn it got the first to work can't get this too.
Code: Select all
....return $row;
}
$inkColor1 = $row['dinkcolor1'];
echo $inkColor1;
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 20, 2006 3:39 pm
$row won't appear without calling the function.
Code: Select all
$row = match_sample(4);
var_dump($row);
purephazer3
Forum Newbie
Posts: 6 Joined: Thu Mar 16, 2006 3:23 pm
Post
by purephazer3 » Mon Mar 20, 2006 3:56 pm
wow, that's awsome thanks...
so I guess
$selInkcolor1 = $row['dinkcolor1'];
$selInkcolor2 = $row['dinkcolor2'];
$selLining = $row['dlining'];
$selMotif = $row['dmotif'];
$selTypestyle1 = $row['dtypestyle1'];
$selTypestyle2 = $row['dtypestyle2'];
was a big waste a code in my function...lol