I'm focusing on an Resource Database problem using PHP / MySQL.

Within this script I must search my assets by an resource id and also have it return all related fields.

First I query the database resource table and discover the asset's type. Then with respect to the type I run 1 of three queries.

<?php

//make database connect
mysql_connect("localhost", "asset_db", "asset_db") or die(mysql_error());
mysql_select_db("asset_db") or die(mysql_error());

//get type of asset
$type = mysql_query("
SELECT asset.type
From asset
WHERE asset.id = 93120
")
or die(mysql_error());

switch ($type){
    case "Server":
        //do some stuff that involves a mysql query
        mysql_query("
        SELECT asset.id
        ,asset.company
        ,asset.location
        ,asset.purchase_date
        ,asset.purchase_order
        ,asset.value
        ,asset.type
        ,asset.notes
        ,server.manufacturer
        ,server.model
        ,server.serial_number
        ,server.esc
        ,server.user
        ,server.prev_user
        ,server.warranty
        FROM asset
        LEFT JOIN server
        ON server.id = asset.id
        WHERE asset.id = 93120
        ");
        break;
    case "Laptop":
        //do some stuff that involves a mysql query
        mysql_query("
        SELECT asset.id
        ,asset.company
        ,asset.location
        ,asset.purchase_date
        ,asset.purchase_order
        ,asset.value
        ,asset.type
        ,asset.notes
        ,laptop.manufacturer
        ,laptop.model
        ,laptop.serial_number
        ,laptop.esc
        ,laptop.user
        ,laptop.prev_user
        ,laptop.warranty
        FROM asset
        LEFT JOIN laptop
        ON laptop.id = asset.id
        WHERE asset.id = 93120
        ");
        break;  
    case "Desktop":
        //do some stuff that involves a mysql query
        mysql_query("
        SELECT asset.id
        ,asset.company
        ,asset.location
        ,asset.purchase_date
        ,asset.purchase_order
        ,asset.value
        ,asset.type
        ,asset.notes
        ,desktop.manufacturer
        ,desktop.model
        ,desktop.serial_number
        ,desktop.esc
        ,desktop.user
        ,desktop.prev_user
        ,desktop.warranty
        FROM asset
        LEFT JOIN desktop
        ON desktop.id = asset.id
        WHERE asset.id = 93120
        ");
        break;  
}

?>

To date I can get resource.type into $type. Wouldso would Time passes about obtaining the relaxation from the variables (laptop.model to $model, resource.notes to $notes and so forth)?

Thanks.

What you are doing won't work:

$type = mysql_query("
SELECT asset.type
From asset
WHERE asset.id = 93120
")

This puts a resultset into $type, not the kind itself.

After you accomplish that, you have to fetch a row, then fetch the area:

$result = mysql_query("
SELECT asset.type
From asset
WHERE asset.id = 93120
")
if($row = mysql_fetch_object($result)){
  $type = $row->type;

  // NOW you have the type in $type. Do something similar with the rest of the queries.
}

I suppose you would like to make a move such as this:

$result = mysql_query($query);
$i = array();
while ($data = mysql_fetch_assoc($result)) {
 $i[] = $data;
}

This could make $i a multidimensional array that contains all your query data and you could utilize it by doing the next

foreach ($i as $key => $value) {
  echo $value['model'];
  echo $value['serial'];
  etc......
}

You might have a look at http://php.net/manual/en/function.mysql-query.php.

A mysql_query returns an origin which consists of the outcomes of the query. This resource could be read the following way:

$sql_result = mysql_query( [here your stuff] );
while ($row = mysql_fetch_assoc($sql_result)){
  echo $row['model']; // prints the model
}

So, you need to loop with the result and traverse each row. row then is definitely an associative array that contains the only fields.

Hope this can help.