an array of data from two mysql tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cleary1981
    New Member
    • Jun 2008
    • 178

    an array of data from two mysql tables

    Hi,

    Im having trouble trying to figure out where to start with this problem. I have two tables.

    module ={module_id, module_name, subtype, height, width, depth, mod_desc, confirmed}

    object ={object_id, module_name, object_name, xpos, ypos, proj_id}

    Given a value for proj_id I have to check wether any records in my table contain this value. If there are records that contain this value I need to create an array of the following {object_name, xpos, ypos, height, width}

    Can anyone help me in creating this array? Heres my code so far

    Code:
    <?php
    require "config.php";
    
    // $proj = $_POST['proj'];
    
    // Get how many records contain proj_id = proj
    $query = mysql_query("SELECT COUNT(*) FROM object WHERE proj_id = '4'");
    $result = mysql_fetch_row($query) or die(mysql_error()); 
    //echo "result: ".$result[0];
    // if zero do nothing
    if ($result != 0) {
    	
    }
    
    ?>
  • cleary1981
    New Member
    • Jun 2008
    • 178

    #2
    Sorted. heres the code for future reference

    Code:
    <?php
    require "config.php";
    
    // $proj = $_POST['proj'];
    $proj_id = 77;
    // Get how many records contain proj_id = proj
    $query = mysql_query("SELECT COUNT(*) FROM object WHERE proj_id = $proj_id");
    $result = mysql_fetch_row($query) or die(mysql_error()); 
    // echo "result: ".$result[0];
    // if zero do nothing
    if ($result != 0) {
    	$results = mysql_query("SELECT object_name, xpos, ypos, height, width FROM object, module WHERE object.module_name = module.module_name AND proj_id=$proj_id") or die();
    	while($values = mysql_fetch_array($results)){
         echo $values['object_name'] . '<br />';
         echo $values['xpos'] . '<br />';
         echo $values['ypos'] . '<br />';
         echo $values['height'] . '<br />';
         echo $values['width'] . '<br /><br />';
    	}
    	
    }
    ?>

    Comment

    Working...