xiao Posted January 19, 2008 Share Posted January 19, 2008 Is it possible to get this into 1 query? $query = "SELECT * FROM jobs WHERE werkgever_id='".$rij['id']."'"; $query = mysql_query($query) or die("Fout in query"); $tot_jobs = mysql_num_rows($query); $query = "SELECT * FROM jobs WHERE (werkgever_id='".$rij['id']."' AND status='1')"; $query = mysql_query($query) or die("Fout in query"); $act_jobs = mysql_num_rows($query); $query = "SELECT * FROM jobs WHERE (werkgever_id='".$rij['id']."' AND status='2')"; $query = mysql_query($query) or die("Fout in query"); $afg_jobs = mysql_num_rows($query); $query = "SELECT * FROM jobs WHERE (werkgever_id='".$rij['id']."' AND status='0')"; $query = mysql_query($query) or die("Fout in query"); $te_valideren = mysql_num_rows($query); And could you maybe also explain what PHP code I need to use to display the 4 variables? Because I'm not really familiar with AS and GROUP BY etc. Thank you Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 Something like this, just change the mysql_num_rows variable to go with $statusid. Also, you should probably use COUNT instead, since it seems you just care about how many rows return. $statusid = 1 $query = "SELECT * FROM jobs WHERE (werkgever_id='".$rij['id']."' AND status='$statusid')"; $query = mysql_query($query) or die("Fout in query"); $act_jobs = mysql_num_rows($query); Quote Link to comment Share on other sites More sharing options...
xiao Posted January 19, 2008 Author Share Posted January 19, 2008 I currently have this, which makes sence I think: $query = "SELECT count(werkgever_id) AS tot_jobs, status FROM jobs WHERE werkgever_id = '{$rij['id']}' GROUP BY status"; $query = mysql_query($query); $rij = mysql_fetch_array($query); But I don't know how to display the results seperately in PHP, without using a while loop. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2008 Share Posted January 19, 2008 You mean from here? $rij = mysql_fetch_array($query); You have to use a while ($rij) loop if you want to go through each array. Quote Link to comment Share on other sites More sharing options...
xiao Posted January 19, 2008 Author Share Posted January 19, 2008 Isn't there a way to do this without using a while loop? Because I need to use them at different places around the page. Quote Link to comment Share on other sites More sharing options...
xiao Posted January 20, 2008 Author Share Posted January 20, 2008 bump Quote Link to comment Share on other sites More sharing options...
xiao Posted January 21, 2008 Author Share Posted January 21, 2008 ^ Quote Link to comment Share on other sites More sharing options...
fenway Posted January 21, 2008 Share Posted January 21, 2008 Isn't there a way to do this without using a while loop? Because I need to use them at different places around the page. I have no idea what this means... obviously, you have to iterate through the records st! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 You can load them all into an array (using a while loop). Then get the entries from the array throughout your page. Quote Link to comment Share on other sites More sharing options...
xander85 Posted January 21, 2008 Share Posted January 21, 2008 Once you performed your query and you don't want to use the entire array at once, simply use something like this: $rij['0'], $rij['1'], etc..... Since you are fetching as an array you don't even need to use a while loop to actually construct the array, it is done by php. Quote Link to comment Share on other sites More sharing options...
xiao Posted January 22, 2008 Author Share Posted January 22, 2008 Yea, that's what I thought and wanted to know, thank you. Quote Link to comment 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.