thugsr Posted January 28, 2012 Share Posted January 28, 2012 Hi guy's, i have 2 tables and in both i need to cheack some variable, and i don't know how! I tried with mysql_num_rows, but it need to have min one as value. i cheacked in first table and if the table dosn't have that in it, i need to try with other one, but i dont know how! i hope you understand what is the problem! Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/ Share on other sites More sharing options...
SergeiSS Posted January 28, 2012 Share Posted January 28, 2012 What is the word 'cheack'? Do you mean 'check'? I suggest that you mean 'check' Could you show the PHP code and SQL requests that you used? Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312033 Share on other sites More sharing options...
thugsr Posted January 28, 2012 Author Share Posted January 28, 2012 yes i mean check! sorry for that! i delete that part of my code because didn't work, i tried something like this $nesto="SELECT * FROM projekat WHERE naziv= '$value' "; $res=mysql_query($nesto); $num_rows = mysql_num_rows($resultat); if (num_rows>0) { //some code } else { $nesto="SELECT * FROM zadatak WHERE naziv= '$value' "; $res=mysql_query($nesto); $num_rows = mysql_num_rows($resultat); //and here again some code } Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312036 Share on other sites More sharing options...
litebearer Posted January 28, 2012 Share Posted January 28, 2012 for starters... $res does not equal $resultat $res=mysql_query($nesto); $num_rows = mysql_num_rows($resultat); Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312039 Share on other sites More sharing options...
SergeiSS Posted January 28, 2012 Share Posted January 28, 2012 What is the variable $resultat? Where do you assign it? It seems that you must write here $res, but not $resultat $res=mysql_query($nesto); $num_rows = mysql_num_rows($res); Только так будет правильно. Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312040 Share on other sites More sharing options...
thugsr Posted January 28, 2012 Author Share Posted January 28, 2012 i know that, i wrote that unconsciously...my problem isn't that, my problem is that mysql_num_rows must be > then 0, and if it is 0 there is error that say that...i must change somehow that if statement, but i dont know what to put in it... Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312043 Share on other sites More sharing options...
SergeiSS Posted January 28, 2012 Share Posted January 28, 2012 Well... You'd better start just one request. And also you need COUNT() function. $sql="select ( "SELECT count(*) FROM projekat WHERE naziv= '$value' ) as count_1, (SELECT * FROM zadatak WHERE naziv= '$value' ) as count_2"; Start this request and check values of count_1 and count_2. count_1 shows the number of rows in one table, satisfied your condition, count_2 shows the same in the second table. I hope you'll find what you need. Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312050 Share on other sites More sharing options...
thugsr Posted January 28, 2012 Author Share Posted January 28, 2012 for example i have two tables in witch are students and profesors. when i log in i redirect students at theirs page and profesors on other page. but i have some pages that are same for both students and profesors. in some area of my page i have echo witch displays name of profesor/student! and now i need to check in both tables to find is it profesor or student and echo their name, i tried with num_rows, and that way dosnt work for me. the num_row counter is only to try to see if the table contains that value. and if contains i do select of it and echo names, but that way like i said doesn't work! i hope that now i better explaind what i need. Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312053 Share on other sites More sharing options...
SergeiSS Posted January 28, 2012 Share Posted January 28, 2012 You mean you don't know how to read values from the selection that you performed? Do it in this way: $nesto="SELECT * FROM projekat WHERE naziv= '$value' "; $res=mysql_query($nesto); $num_rows = mysql_num_rows($res); if (num_rows>0) { while( $row=mysql_fetch_assoc( $res ) ) { // all values from every row is here, in an array $row, that have associative keys .... } } Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312058 Share on other sites More sharing options...
thugsr Posted January 28, 2012 Author Share Posted January 28, 2012 no,no,no i'm not so noob! that is for one table, and for other in same place? i have at login in some variable that contains email from loged user! now i need to check in some pages is it loged profesor or student! i need to check bot table to see who is loged! i solved it with session in witch i store value of role! if role is 2 it is student and i select student from table, else if 3 it is profesor and i select profesor... Quote Link to comment https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/#findComment-1312067 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.