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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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