Is mra_number the primary key or have a unique index (i.e. can you ever get more than one row)? If so, you could do something like:
PHP Code:
function shipQuery($mra_num)
{
$mra_num = (int)$mra_num; // force integer to prevent SQL injection
$shipping_query = mysql_query("SELECT * FROM shipping WHERE mra_number='$mra_num'");
if(mysql_num_rows($shipping_query))
{
return(mysql_fetch_assoc($shipping_query)); // use fetch_assoc
}
return false;
}
If you can get more than one row, then:
PHP Code:
function shipQuery($mra_num)
{
$mra_num = (int)$mra_num; // force integer to prevent SQL injection
$data = array();
$shipping_query = mysql_query("SELECT * FROM shipping WHERE mra_number='$mra_num'");
while ($ship = mysql_fetch_assoc($shipping_query)) { // fetch_assoc
$data[] = $ship;
}
return $data;
}
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Just assign the return value of the function to a variable (which will be an array):
PHP Code:
$ship = shipQuery($mra);
if(!empty($ship))
{
echo "Hello, " . $ship['fname'];
}
else
{
echo "No matching data found.";
}
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks