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) { } ?> Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/ Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Did you know about: mysql_fetch_array Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621830 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 Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621833 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 ?> Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621837 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? Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621841 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 Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621842 Share on other sites More sharing options...
cleary1981 Posted August 21, 2008 Author Share Posted August 21, 2008 Thanks guys. thats working now Link to comment https://forums.phpfreaks.com/topic/120671-solved-an-array-of-data-from-two-mysql-tables/#findComment-621846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.