Jump to content

Recommended Posts

public function ListProduct($Order) {

$sql = "SELECT `Order`.`OrderNumber` , `Despatch`.`OrderNumber` ,

`Stock`.`ProductCode` , `Stock`.`Description` , `Stock`.`ProductGroup` , `Stock`.`Size` , `Stock`.`IPICODE`

FROM `Stock` , `Despatch` ,`Order`

WHERE `Order`.`OrderNumber` = '" . $Order. "'

AND`Order`.`OrderNumber` = `Despatch`.`OrderNumber`

AND`Despatch`.`Product`= `Stock`.`ProductCode`

";

 

// echo $sql;

mysql_select_db(DB_DATABASE_NAME, $this->conn);

$result = mysql_query($sql, $this->conn);

//$num_rows = mysql_num_rows($result);

//echo "Number of rows : $num_rows";

 

while($row = mysql_fetch_array($result)) {

if($row[0] != "") {

$result = mysql_query($sql, $this->conn);

$num_rows = mysql_num_rows($result);

//echo "Number of rows : $num_rows";

}

 

else {

 

$sql = "SELECT `Order`.`OrderNumber` , `Despatch`.`OrderNumber` ,

`Stock`.`ProductCode` , `Stock`.`Description` , `Stock`.`ProductGroup` , `Stock`.`Size` , `Stock`.`IPICODE`

FROM `Stock` , `Despatch` ,`Order`

WHERE `Order`.`OrderNumber` = '" . $Order. "'

AND`Order`.`ProductCode`= `Stock`.`ProductCode`

 

";

mysql_select_db(DB_DATABASE_NAME, $this->conn);

$result = mysql_query($sql, $this->conn);

$num_rows = mysql_num_rows($result);

//echo "Number of rows : $num_rows";

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$return[] = $row;

}

return $return;

return $num_rows;

 

 

}

 

}

 

 

I have the query above which check if any rows are returned from the first sql statement and if the rows are empty, the aim is to run the second query and returns results. However i am going wrong somewhere. Can someone have a look. Perhaps i am over complicating this?

Link to comment
https://forums.phpfreaks.com/topic/271347-mysql-query-with-two-forks/
Share on other sites

First order of business is to use the [code][/code] tags around your code, and proper intending. The latter can be a bit tricky on this forum, unfortunately, but just use the "Paste as plain text" button (second from the right, top row) and it'll work.

 

Second order of business is never to run queries inside loops; Nothing kills performance like this. Depending upon your exact intentions you'll either want to use JOINs, or a loop to construct the secondary query/queries.

 

If you still require some assistance, please follow at least the first step. Also, f you could post a more thorough explanation of what, exactly, you want to do, then I'm sure someone here can help you.

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.