Jump to content

[SOLVED] Combining queries


xiao

Recommended Posts

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

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.