By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,013 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

an array of data from two mysql tables

100+
P: 178
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3.  
  4. // $proj = $_POST['proj'];
  5.  
  6. // Get how many records contain proj_id = proj
  7. $query = mysql_query("SELECT COUNT(*) FROM object WHERE proj_id = '4'");
  8. $result = mysql_fetch_row($query) or die(mysql_error()); 
  9. //echo "result: ".$result[0];
  10. // if zero do nothing
  11. if ($result != 0) {
  12.  
  13. }
  14.  
  15. ?>
Aug 21 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 178
Sorted. heres the code for future reference

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require "config.php";
  3.  
  4. // $proj = $_POST['proj'];
  5. $proj_id = 77;
  6. // Get how many records contain proj_id = proj
  7. $query = mysql_query("SELECT COUNT(*) FROM object WHERE proj_id = $proj_id");
  8. $result = mysql_fetch_row($query) or die(mysql_error()); 
  9. // echo "result: ".$result[0];
  10. // if zero do nothing
  11. if ($result != 0) {
  12.     $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();
  13.     while($values = mysql_fetch_array($results)){
  14.      echo $values['object_name'] . '<br />';
  15.      echo $values['xpos'] . '<br />';
  16.      echo $values['ypos'] . '<br />';
  17.      echo $values['height'] . '<br />';
  18.      echo $values['width'] . '<br /><br />';
  19.     }
  20.  
  21. }
  22. ?>
Aug 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.