Jump to content

[SOLVED] Mulriple Mysql Queries


leest

Recommended Posts

Hi,

 

Just a little question really, I have a query which draws information from a table, i want to take two of the results from the table and run two more queries.  Now i can do this simply enough if i just wanted display one set of results, however i wanted to paginate the script and get multiple results but really not sure how to go about it, as i can not seem to run more than one query within the pagination.  Any advce or a good kick in the right direction would be much appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/82230-solved-mulriple-mysql-queries/
Share on other sites

HI,

 

Thanks ok below is a basic layout of what i am trying to do, this isn't my actual script but i can get the results that i want from this.  What i want to do now is to find away to paginate the results or two run the queries differntly.

 


include '../folder/folder/db1.php';

$result_1 = $row['result_1'];
// Make a MySQL Connection
$query = "SELECT * FROM Table WHERE Result_1 ='$result_1'  "; 

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());

$answer_1 = $row['answer_1'];
$answer_2 = $row['answer_2'];
$answer_3 = $row['answer_3'];
}

$query = "SELECT * FROM Table2 WHERE answer_2 ='$answer_2'  "; 

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());

$answer_4 = $row['answer_4'];
}

$query = "SELECT * FROM Table3 WHERE answer_3 ='$answer_3'  "; 

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());

$answer_5 = $row['answer_5'];

echo $row['answer_1'];
echo $row['answer_4'];
echo $row['answer_5'];
}

How about a query like:

  SELECT *
  FROM `table1` t1
  INNER JOIN `table2` t2 ON t1.`answer_2`=t2.`answer_2`
  INNER JOIN `table3` t3 ON t1.`answer_3`=t3.`answer_3`

 

And then you can add the appropriate LIMIT clause for your pagination?

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.