Jump to content

Cheack some value in 2 tables


thugsr

Recommended Posts

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! :)

Link to comment
https://forums.phpfreaks.com/topic/255949-cheack-some-value-in-2-tables/
Share on other sites

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
}

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.

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.

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
    ....
  }
} 

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.