Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible?

Status
Not open for further replies.

andy98

Programmer
Jul 7, 2000
120
GB
I have a query that produces the results which displays what I need from my query except the last column in my table needs to have its result from a different query.

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

echo "<tr><td>$row[cust_id]</td>"; 
echo "<td>$row[cust_name_last]</td>";
echo "<td><a href='listwarrant.php?warrant_id=$row[warrant_id]'>";
echo "<img src='./images/issues.gif'></a></td>";
}

I need to be able to have a different query produce the result for the last column in my table. Is this possible?

 
yes, why not? at least you gonna have 2 queries, but you should be able to do it with only one. do you have an example? an example from me:

select i.id as id, i.name as name, w.warrant from ident i, warranties w where i.id=w.id

this is only an example.
 
No, I can't use the same query for the results because the query is determined by a search page and I don't want to join the 2 tables together in one query because it will not perform the correct search results.

Is it possible to reference another query result for my last table column variable?

 
hmmm... then I don't understand the question, could you pls post an example?

thanks.
 
It should definetly be possible.
I don't have access to test, but do it like this...

The trick is that you have to get rid of your while statement.
The 'while' refers to only one query.

Do it something like this...

$sql = count(*)
$sql2 = get some data using the key $i
$sql3 = echo the data using the key $i

for ($i < $sql) {
$sql2 = echo the data using the key $i
$sql3 = get some data using the key $i
}


Hope this helps...
 
Just in case anyone else wanted to know how to do something similar, I solved this by simply having another query within my array:

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

put your second query here... SELECT * FROM ..
                              WHERE cust_id = $row[cust_id]

Then I used an IF statement to test for mysql_num_rows on the second query.

The results of this then decided whether or not I needed to display the results from that query.

Hope that helps someone else in the future!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top