dont_be_hasty Posted February 3, 2009 Share Posted February 3, 2009 Hi Im pretty new to php and could with some help. I have the following tables in my database: term(id, name) path(path_id, term1_id, term2_id) Basically the user inputs 2 term names, i use these names to get the ids of the terms and display it on screen. I now need to use display the path_id of the 2 terms (using term1_id and term2_id). Heres my code: $term1 = mysql_real_escape_string($_POST['term1']); $term2 = mysql_real_escape_string($_POST['term2']); $t1="SELECT term1_id FROM path INNER JOIN term ON (path.term1_id=term.id) WHERE name = '$term1'"; $t2="SELECT term2_id FROM path INNER JOIN term ON (path.term2_id=term.id) WHERE name = '$term2'"; $result_t1=mysql_query($t1) or die(mysql_error()); $result_t2=mysql_query($t2) or die(mysql_error()); $rowt1 = mysql_fetch_assoc($result_t1); $rowt2 = mysql_fetch_assoc($result_t2); When i display rowt1 and rowt2, it displays the correct results. However when i add the following, code to it, it does not display the path_id. $query1="SELECT path_id FROM path WHERE term1_id = '$rowt1' AND term2_id = '$rowt2'"; $result1=mysql_query($query11) or die(mysql_error()); $row1 = mysql_fetch_assoc($result11); If i manually set term1_id and term2_id ($term1_id="1"- the second part does work correctly. They dont seem to work together. I new to php/mysql and do not if im using the correct functions. Any help would be great. Link to comment https://forums.phpfreaks.com/topic/143688-solved-phpmysql-help/ Share on other sites More sharing options...
flyhoney Posted February 3, 2009 Share Posted February 3, 2009 $rowt1 = mysql_fetch_assoc($result_t1); $rowt2 = mysql_fetch_assoc($result_t2); $query1="SELECT path_id FROM path WHERE term1_id = '$rowt1' AND term2_id = '$rowt2'"; $rowt1 and $rowt2 are associative arrays. You prolly want something more like this: $rowt1 = mysql_fetch_assoc($result_t1); $rowt2 = mysql_fetch_assoc($result_t2); $query1="SELECT path_id FROM path WHERE term1_id = '$rowt1[term1_id]' AND term2_id = '$rowt2[term2_id]'"; Link to comment https://forums.phpfreaks.com/topic/143688-solved-phpmysql-help/#findComment-753974 Share on other sites More sharing options...
dont_be_hasty Posted February 4, 2009 Author Share Posted February 4, 2009 Worked a treat. Thanks so much, i sat for ages trying to get that to work. I never was good with arrays, lol. Link to comment https://forums.phpfreaks.com/topic/143688-solved-phpmysql-help/#findComment-754284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.