cleary1981 Posted August 21, 2008 Share Posted August 21, 2008 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 <?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) { } ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Did you know about: mysql_fetch_array Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted August 21, 2008 Author Share Posted August 21, 2008 Yeah but what is confusing me is implementing it for values from two tables at once Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 21, 2008 Share Posted August 21, 2008 <?php $proj_id = 4; //a get variable probably $results = mysql_query("SELECT object_name, xpos, ypos, height, width FROM object WHERE 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 />'; } ?> In your case there's no need to query two tables, as you aren't showing the project name from the project id. If so, modify your query to something like this: <?php $results = mysql_query("SELECT object_name, xpos, ypos, height, width, project_name FROM object obj INNER JOIN project proj ON obj.proj_id=proj.id WHERE obj.proj_id=$proj_id"); //project_name and any other fields can be called like the previous code snippet ?> Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted August 21, 2008 Author Share Posted August 21, 2008 But the two tables are joined by module_name can it not be joined that way? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 21, 2008 Share Posted August 21, 2008 SELECT * FROM object, module WHERE object.module_name = module.module_name Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted August 21, 2008 Author Share Posted August 21, 2008 Thanks guys. thats working now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.